Setting Up Common Authorized Keys File for Shared Access
In this article, we will discuss how to set up a common authorized keys file for shared access between two users. This is a common scenario in a multi-user system where you want to grant access to a shared resource or allow one user to perform actions on behalf of another user. We will cover the key concepts, steps, and best practices for implementing this setup on a typical Unix-like system.
What are Authorized Keys?
Authorized keys are a way to authenticate users without requiring a password. This is achieved through the use of public key cryptography. Each user has a pair of keys: a public key and a private key. The public key is stored in a file called authorized\_keys on the server, and the private key is kept securely by the user on their local machine.
When a user attempts to connect to the server, the server checks the authorized\_keys file for the user's public key. If it finds a match, the user is authenticated and granted access. This is a more secure method of authentication than using passwords, as it is resistant to brute-force attacks and does not rely on the user choosing a strong password.
Setting Up a Common Authorized Keys File
To set up a common authorized keys file for shared access between two users, we will first create a new group for the users and add them to it:
sudo groupadd keys
sudo usermod -a -G keys user1
sudo usermod -a -G keys user2
Next, we will create a new file in the ~/.ssh/ directory for the common authorized keys:
sudo mkdir ~/.ssh/
sudo touch ~/.ssh/common\_authorized\_keys
We will then change the ownership and permissions of the new directory and file:
sudo chown -R user1:keys ~/.ssh/
sudo chmod 700 ~/.ssh/
sudo chmod 600 ~/.ssh/common\_authorized\_keys
Finally, we will append the public keys for both users to the common\_authorized\_keys file:
cat ~/.ssh/id\_rsa.pub >> ~/.ssh/common\_authorized\_keys
sudo chown user2:keys ~/.ssh/common\_authorized\_keys
cat ~/.ssh/id\_rsa.pub >> ~/.ssh/common\_authorized\_keys
sudo chown user1:keys ~/.ssh/common\_authorized\_keys
After these steps, both users will be able to use the public keys in the common\_authorized\_keys file for authentication when connecting to the server.
Best Practices
Here are some best practices to keep in mind when setting up a common authorized keys file:
-
Keep the
common\_authorized\_keysfile secure. Only the users in thekeysgroup should have read and write access. -
Use a strong passphrase for the private key. This provides an additional layer of security in case the private key is compromised.
-
Regularly review the
common\_authorized\_keysfile. Remove any keys that are no longer needed or that belong to users who no longer require access. -
Consider using a configuration management tool such as Ansible or Puppet to automate the process of setting up and managing authorized keys.
In this article, we covered the process of setting up a common authorized keys file for shared access between two users. We discussed the key concepts, steps, and best practices for implementing this setup. With this knowledge, you can grant secure access to shared resources and allow users to perform actions on behalf of one another.