简体   繁体   中英

How can I add users with different SSH keys in Linux?

On my Linux server I have configured the root user to use an SSH key, and I added a new user with SSH key access, but that user can use the same key. I want to know if this is normal, or if each user should have a unique key for signing in remotely.

When I configured the new user, I switched to that user then pasted the contents of the id_rsa.pub file that was generated when I created an SSH key for the root user to /home/user/.ssh/authorized_keys . This is probably why they both have the same key, but when I tried generating a new key and pasting the id_rsa.pub file contents for that key instead I got a (publickey) error when I tried logging in as the new user.

In other words, if the the two users don't share the same id_rsa.pub contents I can't login with the one that's different. How can I configure it so that each user has a unique key?

It's a bad idea to give regular users the same ssh key as root; nothing would stop them from logging in as root instead of their own user identity. And it's generally a bad idea to let root log in at all once you have a regular user set up. Use sudo or su from a regular user account. To use a different key for each user, you need the matching private key on the client machine your user is logging in from.

If the user name on the client matches the user name on the server and the private key matching the id_rsa.pub you added to the server's /home/user/.ssh/authorized_keys is stored on the client as /home/user/.ssh/id_rsa then you can log into the server with a simple ssh server_name (or server ip). If the user name on the client doesn't match, then you need the server user, ie, ssh server_user@server_name . And if the private key is somewhere other than /home/user/.ssh/id_rsa, you need ssh -i /path/to/private.key server_user@server_name .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM