Linux – Setup public key authorized SSH for non-root users

centoslinuxpublic-keysshssh-keys

I was able to setup ssh login using public keys for root users and tried to apply the same logic for non-root users. I have tried to troubleshoot this issue in vain. I am using centos for both my local machine and remote server.

Here is a gist of my sshd_config file a my remote server,

RSAAuthentication yes
PublicKeyAuthentication yes
AuthorizedKeysFile /etc/ssh/user/authorized_keys

PasswordAuthentication no

UsePAM no

PermitRootLogin without-password

I have moved my authorized keys file away from the user's home to /etc/ssh/user/authorized_keys as I read about home dir encryption in centos.

I have also changed the ownership of all files/dirs associated to the non-root user.

Not sure what step I am missing in my config as the same config works very well for root remote logins.

Best Answer

Remove the authorized_keys entry in your config file. Restart sshd. Make a .ssh directory in your non-root user home directory. Put the key in a file called ~/.ssh/authorized keys. Make the directory 0700 and the authorized_keys file 0644. Do the same for the root user.