1、編輯config文件
vim ~/.ssh/config
在文件添加:
Host test
HostName 120.0.0.1
User root
Port 22
IdentityFile ~/.ssh/id_rsa
2、上傳文件到服務器,並輸入密碼
scp ~/.ssh/id_rsa.pub test:~/.ssh
3、登陸服務器,並輸入密碼
ssh test
4、將上傳文件追加到指定文件後刪除文件
cd ~/.ssh
cat id_rsa.pub >> authorized_keys
rm -rf id_rsa.pub
5、然後直接登陸即可
ssh test