Setting Up a Common Authorized Keys File for Shared Access

Abstract: Configure SSH to use per-user public keys in a group-owned directory, enabling secure shared access without root privileges or global key exposure.

Created: 2026-08-20 by
To enable shared SSH access for multiple users, you must configure a dedicated group and place the authorized keys file in a directory owned by that group. This approach allows members of the group to read and append their public keys without requiring root privileges or compromising system security. The solution relies on proper file permissions rather than changing the global sshd_config to point to a root-owned file, which would break authentication for non-root users.

The Security Problem with Root-Owned Keys

A common misconception is that setting AuthorizedKeysFile /root/.ssh/authorized_keys in /etc/ssh/sshd_config allows any user to log in using keys stored in the root home directory. This configuration is fundamentally broken because the SSH daemon drops privileges before reading the authorized keys file. If the file is owned by root and has restrictive permissions (typically 600), non-root users cannot read it, resulting in an "Authentication failed" error. Even if you make the file world-readable, storing private user keys in a shared location violates basic security principles regarding key isolation and audit trails. You should never attempt to share a single authorized keys file across users by making it globally readable or writable by all users, as this creates a significant security vulnerability where one compromised account could inject malicious keys for others.

Creating a Shared Access Group

The correct method involves creating a specific Linux group that will manage access to the shared resources. First, create a new group named sshshared using the groupadd command. Then, add the users who need shared access to this group using usermod -aG sshshared username. This ensures that only designated users have the ability to interact with the shared authentication mechanism. It is crucial to use the -a flag to append the group to the user's existing groups, preventing the removal of other necessary group memberships. After adding users, verify the group membership with the groups command to ensure the configuration is applied correctly.

Setting Up the Directory Structure

Next, create a dedicated directory to store the authorized keys files. A standard location is /etc/ssh/shared_authorized_keys. Create this directory using mkdir -p /etc/ssh/shared_authorized_keys. Change the ownership of this directory to the sshshared group using chown root:sshshared /etc/ssh/shared_authorized_keys. Set the permissions to 750, which allows the owner (root) full control, the group to read and execute, and denies access to others. This permission structure ensures that only members of the sshshared group can list and access the keys within this directory. Inside this directory, create individual files for each user, such as /etc/ssh/shared_authorized_keys/user1.pub. Each file should be owned by the respective user but readable by the group. For example, set the permissions to 640 so that the owner can write and the group can read.

Configuring SSH Daemon Settings

Modify the sshd_config file located at /etc/ssh/sshd_config to include the shared keys directory. Add the following line to the configuration: AuthorizedKeysFile /etc/ssh/shared_authorized_keys/%u.pub .ssh/authorized_keys. The %u placeholder is replaced by the username during authentication, allowing the system to look for a specific file for each user while also falling back to the traditional .ssh/authorized_keys location. This hybrid approach provides flexibility, allowing users to maintain personal keys alongside shared ones. After editing the configuration file, restart the SSH service using systemctl restart sshd to apply the changes. Test the connection from a client machine to ensure that users can authenticate successfully using their respective public keys.

Maintaining and Securing the Setup

Regularly audit the contents of the shared directory to ensure that only authorized keys are present. Remove any obsolete keys promptly to maintain a clean and secure environment. Consider implementing additional security measures such as disabling password authentication and enforcing key-based login only. Review the /var/log/auth.log file for any authentication failures or suspicious activities. Implementing these practices helps maintain the integrity of your shared access setup. For more information on securing your server, see Securing an Ubuntu Server for Development Purposes. Additionally, understanding how to lock user accounts is vital for managing access revocation, as detailed in Locking User Accounts with Sudo Commands Without Rebooting.

Frequently Asked Questions

Can I use a single file for all users?

No, using a single file for all users is insecure and difficult to manage. Each user should have their own file to allow for easy revocation and auditing of access rights.

What permissions should the shared directory have?

The shared directory should have permissions set to 750, allowing root full access and the group read and execute permissions. This prevents unauthorized users from accessing the keys.

How do I remove a user from shared access?

To remove a user, simply delete their corresponding public key file from the shared directory and remove them from the sshshared group using gpasswd -d username sshshared.

Does this method affect existing SSH configurations?

No, this method does not affect existing configurations. By including .ssh/authorized_keys in the AuthorizedKeysFile directive, users can still use their personal keys if they exist.

Is it safe to store keys in /etc/ssh?

Yes, storing keys in /etc/ssh is safe as long as the directory permissions are strictly controlled. This location is standard for system-wide SSH configurations and resources.

Tags: Linux Security

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More