if is root account
# chmod 700 ~/.ssh
# chmod 600 ~/.ssh/authorized_keys
change /etc/ssh/sshd_config so it contains AuthorizedKeysFile %h/.ssh/authorized_keys
# sudo service ssh restart
if just a normal user
if you have a ecryptfs private service may you $HOME/.ssh is umount.
you can move AuthorizedKeysFile to other directory
Option 1.All users use the same public key
sudo mkdir /etc/ssh/publicSSHkeys # Create a folder for public SSH keys
sudo mv ~/.ssh/authorized_keys /etc/ssh/publicSSHkeys/ # Move the authorized_keys file there
sudo nano /etc/ssh/sshd_config # Modify sshd_config to the new location
change this… “AuthorizedKeysFile %h/.ssh/authorized_keys“
to this… “AuthorizedKeysFile /etc/ssh/publicSSHkeys/authorized_keys“
sudo service sshd reload # Then you just need to reload the server
Option 2. All users use different public key
mkdir /etc/ssh/USERNAME
chmod 755 /etc/ssh/USERNAME
chown USERNAME /etc/ssh/USERNAME
touch /etc/ssh/USERNAME/authorized_keys
chmod 644 /etc/ssh/USERNAME/authorized_keys
chown USERNAME /etc/ssh/USERNAME/authorized_keys
cat /home/USERNAME/.ssh/authorized_keys > /etc/ssh/USERNAME/authorized_keys
echo "AuthorizedKeysFile /etc/ssh/%u/authorized_keys" >> /etc/ssh/sshd_config
正文完