key login for SSH normal user (non-root user)
This takes the username Zhangsan as an example.
Because of personal habits, I changed the user Zhangsan default directory, in the process of using the key to log in, always prompted to enter the user password, and/var/log/secure also did not have any information,
Later in the/etc/passwd the default directory changed back to/home/zhangsan, it is normal. Cause I've been tossing around all day ...
The following is a brief description of the key login steps for SSH non-root user:
1, generate key pair (key pair)
Ssh-keygen-t rsa-c "Zhangsan@mail.com"
Enter file in which to save the key (/ROOT/.SSH/ID_RSA):
#输入key的保存位置, you can enter directly.
Enter passphrase (empty for no passphrase):
#私钥口令, do not need to return directly to the word.
2, add public key to Authorized_keys file
Mkdir/home/zhangsan/.ssh
touch/home/zhangsan/.ssh/authorized_keys
cat/root/.ssh/id_rsa.pub >/home/ Zhangsan/.ssh/authorized_keys
Note Permissions for directories and files
/home/zhangsan/.ssh's owner is supposed to be zhangsan:group.
chmod 700/home/zhangsan/.ssh
chmod 600/home/zhangsan/.ssh/authorized_keys
Login Test
Ssh-i/home/zhangsan/.ssh/id_rsa zhangsan@127.0.0.1
If it is Xshell and other client tools, import the private key Id_rsa.