- 第一步
ssh-keygen -t rsa -f ~/.ssh/id_rsa
输入服务器登录密码 - 第二步
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 8022 zhangsan@10.81.126.118
此时使用 ssh luban@10.81.126.118 -p 8022 命令登录,会如下提示,要求输入私钥
Enter passphrase for key ‘~/.ssh/id_rsa’: - 第三步
将私钥添加到钥匙串中,按照提示输入私钥密码
ssh-add -K ~/.ssh/id_rsa - 第四步
新建config文件,配置config文件,实现免密快速登录
vim ~/.ssh/config
添加
Host zs
User zhangsna
Hostname 10.81.126.118
Port 8022
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
UseKeychain yes
AddKeysToAgent yes - 第五步
ssh zs 直接登录服务器
scp dir_local zs:dir_remote 跳过端口和密码
来源:CSDN
作者:哀酱
链接:https://blog.csdn.net/u010821666/article/details/104064480