ssh链接:
ssh root@192.168.1.250
ssh -p 22222 root@101.201.43.143
输入密码登陆
ssh不用收入密码建立密钥
1、生成秘钥
[root@localhost logs]# ssh-keygen
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:6b:45:21:25:cf:b2:0d:ac:cd:28:d6:1a:a2:32:82:41 root@localhost.localdomainThe key's randomart image is:+--[ RSA 2048]----+| o.o || . = . || E + + ||. . = * ||. . + + S o ||.o o + o ||* . o ||o. . || |+-----------------+2、22号端口把秘钥发过去[root@localhost logs]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.250
root@192.168.1.250's password:
3、非22号端口把秘钥发过去
[root@localhost logs]# ssh-copy-id -i ~/.ssh/id_rsa.pub '-p 22 root@11.11.11.11'
root@101.201.43.143's password:4.ubuntu服务器
#ssh-copy-id root@11.11.11.1 -p 22
下次链接不用收入密码了!
有两个节点node1 node2,也可以是ip地址
1.在node1上生成公钥/私钥对
[hjf@node1 ~]$ ssh-keygen -t rsa12
敲3次回车在/home/hjf 目录下生成.ssh目录,里面有id_rsa,id_rsa.pub
2.把node1下的id_rsa.pub复制到node2下的.ssh/authorized_keys
[hjf@node1 ~]$ scp .ssh/id_rsa.pub hjf@node4:/home/hjf/id_rsa.pub hjf@node2's password:id_rsa.pub 100% 391 0.4KB/s 00:00 1234
第一次连接会输入一个密码,这里用scp复制
3.将node2中的id_rsa.pub追加到.ssh/authorized_keys里,并改变authorized_keys的权限600
[hjf@node2 ~]$ cat id_rsa.pub >>.ssh/authorized_keys[hjf@node2 ~]$ chmod 600 .ssh/authorized_keys123
4.node1 登陆node2
ssh hjf@node2