准备:2台机器,ip分别为:192.168.18.131 192.168.18.130
目的:通过131ssh远程访问130.无需输入密码
1、首先在131上生成密钥对。
#cd /root/.ssh (如果没有.ssh, 请在root目录下mkdir .ssh chmod 755 .ssh)
#ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): (直接回车)
Enter passphrase (empty for no passphrase): (直接回车)
Enter same passphrase again: (直接回车)
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:06:96:6b:56:0c:33:a4:24:16:8c:06:35:9b:98:8b:e7 root@localhost.localdomain
2、在root/.ssh目录下生成密钥对 id_rsa和id_rsa.pub
其中id_rsa是私钥,id_rsa.pub是公钥。
3、将公钥直接copy到130的/root/.ssh目录下
#scp id_rsa.pub root@192.168.18.130:/root/.ssh
4、将130机器上的id_rsa.pub改名为authorized_keys
#cd /root/.ssh
#mv id_rsa.pub authorized_keys
5、密钥设置成功。131ssh访问130无需密码成功
#ssh 192.168.18.130
成功啦
若.ssh目录进不去,删除了再创建.ssh目录,然后chmod 755,然后将服务器的公钥authorized_keys复制到客户端目录下即可。
linux中两台服务器配置ssh免密登录
最新推荐文章于 2024-10-11 10:27:46 发布