[Linux] For super beginners Tips when public key authentication settings do not work

It is an article about the part that was easy to trip for super beginners

I was asked to set up public key authentication, but here are some tips to refer to when authentication does not go well. This is a relatively rudimentary point, but if you make a mistake, you will not be able to authenticate normally, so we have summarized the points that you must be careful about.

Permission issues

The created public key will be added to authorized_keys. Let's set the permission of this authorized_keys to 600.

chmod 600 authorized_keys

600 means that only the owner of the file has read and write permissions. You will be looking at this file with your username when you log in. So let's change the owner and owning group of authorized_keys to the login username. Be careful if you prepare this file as root or create .ssh.

chown username:groupname file name or directory name

You can change the owner with this command.

User public key issue

Is the added public key correct? If you have copied and registered the public key from another server, be careful. Because the person may have multiple private and public keys. .. ..

Also, you need to be careful if there is a public key prepared at the login source (/home/username/.ssh) at the end of the user's directory used for ssh. Since I log in as a deply user at once, I made a mistake thinking that I had to enter the public key of the deploy user who logged in.

The problem of where to put the public key

Are you properly under .ssh? It does not exist immediately after the user is added by the adduser command. Create your own with mkdir and set permissions.

Recommended Posts

[Linux] For super beginners Tips when public key authentication settings do not work
[Amazon Linux 2] Change from public key authentication to password authentication
Spacemacs settings (for beginners)
Set public key authentication when connecting with SSH in Teraterm