Log in using ssh on multiple user accounts using the same id_rsa and id_rsa.pub

i has id_rsaand id_rsa.pub. let's say I have 5 users on one machine. I want to use the same id_rsaand id_rsa.pubfor ssh between users without a password. Is it possible? As I understand it, if user1 wants to do ssh user2@localhost... /home/user2/.sshmust have a file with a name authorized_keyswith the contents id_rsa.pub. and /home/user1/.sshmust have an id_rsa file. therefore by doing this user1 you can do ssh user2@localhost.
But if user2 wants to do ssh user1@localhost, then user1 must have authorized_keyshaving content id_rsa.pub, and user2 must have a fileid_rsa

to summarize, user1 has: authorized_key, id_rsaand user2 has the same files. what happens on my machine: user1 can do ssh user2@localhost, but user2 cannot do user1@localhost.

is there something? is there something i don't understand? Is ssh possible between users using the same id_rsaones id_rsa.pub?

+3
source share
1 answer

Permissions for files in the user directory /home/user/.sshmust be 700, and /home/user/.ssh/authorized_keys- 600. Meanwhile, it is important that all the files in each directory .sshbelong to the user in whose home directory they are. To change ownership ownership recursively, you can:

chown -R username:username /home/username/.ssh

If you have multiple users, and you need to do this for each of them, you can use this loop:

for SSHUSER in user1 user2 user3 user4 user5; do
  # Add the authorized_keys file if it doesn't already exist
  touch /home/$SSHUSER/.ssh/authorized_keys

  # Set its permissions
  chmod 600 /home/$SSHUSER/.ssh/authorized_keys

  # Set directory permissions
  chmod 700 /home/$SSHUSER/.ssh

  # Set ownership for everything
  chown -R $SSHUSER:$SSHUSER /home/$SSHUSER/.ssh
done;
+3

All Articles