I have a home server that I use to play with Linux. At the moment, I’m exploring Docker.
When you try to SSH into your home server you may get the following error message if you have an encrypted home directory, you use SSH keys, and you haven’t actually logged into the server machine yet:
Permission denied (publickey).
The problem is due to the fact that your home folder is encrypted and your authorized_keys file is inside it. The solution is to move your authorized_keys file into a separate /etc/ssh/<username>/ folder where <username> is the name of the user that you are logging in as. Use the following commands to set this up:
sudo bash export username=<username> (replace <username> with your Linux user name) cd /etc/ssh mkdir $username chmod 755 $username chown $username:root $username mv /home/$username/.ssh/authorized_keys $username chmod 644 $username/authorized_keys chown $username:root $username/authorized_keys
Note: For good measure, I’ve removed my ~/.ssh folder as I wasn’t using it for anything else.
Then edit your /etc/ssh/sshd_config and add:
Finally, restart ssh with:
service ssh restart
The next time you connect with SSH you should not have to enter your password and no more permission denied messages.