您的位置:首页 > 运维架构

SSH-无密码相互远程登录

2013-06-13 22:10 225 查看
linux多节点之间可以实现无密码SSH相互远程登录。原理就是在每一个节点上面用ssky-keygen生成自己的公钥和私钥,然后再把自己的公钥分别导入到其它节点上面,就可以实现无密码远程登录了。ssh-keygen 创建公钥和密钥。ssh-copy-id 把本地主机的公钥复制到远程主机的authorized_keys文件上。ssh-copy-id 也会给远程主机的用户主目录(home)和~/.ssh, 和~/.ssh/authorized_keys设置合适的权限 。(1)用 ssh-key-gen 在本地主机上创建公钥和密钥ligh@local-host$ ssh-keygen -t rsaEnter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]Enter passphrase (empty for no passphrase): [Press enter key]Enter same passphrase again: [Pess enter key]Your identification has been saved in /home/jsmith/.ssh/id_rsa.Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.The key fingerprint is: 33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9(2)用 ssh-copy-id 把公钥复制到远程主机上ligh@local-host$ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3ligh@remote-host‘s password:Now try logging into the machine, with ―ssh ?remote-host‘‖, and check in:.ssh/authorized_keys to make sure we haven‘t added extra keys that you weren‘t expecting.注: ssh-copy-id 可把公钥密钥追加到远程主机的 .ssh/authorized_key文件中如果提示:-bash: ssh-copy-id: command not found 是说明在改系统上没有该命令,此命令是由openssh-clients包安装的,在操作系统的光碟中有此包,也可以yum install openssh-clients安装。 [root@centos ~]# which ssh-copy-id
/usr/bin/ssh-copy-id
[root@centos ~]# rpm -qf /usr/bin/ssh-copy-id
openssh-clients-5.3p1-84.1.el6.x86_64

(3) 远程登入ligh@local-host$ ssh remote-hostLast login: Sun Nov 16 17:22:33 2008 from 192.168.1.2注: SSH 不会询问密码了即可远程登录主机
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息