1.生成key
首先創建一個test用戶,然後su - test進入test用戶,執行ssh-keygen -t rsa生成key
生成時可輸入key的存放路徑 Enter file in which to save the key (/home/test/.ssh/id_rsa):
輸入key的密碼,回車後默認沒有密碼 Enter passphrase (empty for no passphrase):
2.配置key
進入生成後的目錄/home/test/.ssh/
目錄下有id_rsa.pub(公鑰)和id_rsa(私鑰)兩個文件
將id_rsa.pub重命名爲authorized_keys,更改權限chmod 600 authorized_keys
如需修改key的密碼,可以使用ssh-keygen -f id_rsa -p,然後輸入新的密碼
3.配置sshd_config
添加以下配置到sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthenticationMethods publickey,password
AuthorizedKeysFile .ssh/authorized_keys
PermitRootLogin yes
完成後重啓sshd,systemctl restart sshd
4.登錄
將私鑰拷到本地電腦,通過xshell登錄