ssh
用户名和密码登录
秘钥登录
[root@localhost ~]# ssh-keygen
[root@localhost ~]# cd /root/.ssh/
[root@localhost .ssh]# ls
id_rsa私钥 id_rsa.pub公钥
[root@localhost .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.2.20
[root@localhost .ssh]# ssh-copy-id -i root@192.168.2.20
[root@localhost .ssh]# ssh-copy-id root@192.168.2.20
yes
密码
验证:
[root@localhost .ssh]# ssh root@192.168.2.20
Last login: Sun Aug 30 23:41:11 2020
[root@localhost ~]# ip a
[root@localhost ~]# exit
登出
Connection to 192.168.2.20 closed.
如果想要重新生成秘钥
需要client和服务都删除秘钥目录 重新生成和传递秘钥
client
[root@localhost ~]# rm -rf /root/.ssh/
服务端
[root@localhost ~]# rm -rf /root/.ssh/
client
[root@localhost ~]# ssh-keygen #生成新秘钥
[root@localhost ~]# ssh-copy-id root@192.168.2.20 #传递给服务端
[root@localhost ~]# ssh-add #将新的秘钥添加
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
服务端
[root@localhost ~]# ssh-agent #将秘钥重载
SSH_AUTH_SOCK=/tmp/ssh-4JXYYHs9Otps/agent.17483; export SSH_AUTH_SOCK;
SSH_AGENT_PID=17484; export SSH_AGENT_PID;
echo Agent pid 17484;
[root@localhost ~]# ssh root@192.168.2.20
Last login: Fri Oct 15 17:02:32 2021 from 192.168.2.10
[root@localhost ~]# exit
linux ssh 基础服务
2021/11/30 7:58:48