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.
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.
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.
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.