现在的位置: 首页 > 综合 > 正文

ssh免密码登录

2013年06月04日 ⁄ 综合 ⁄ 共 839字 ⁄ 字号 评论关闭
Linux 为例方便ssh登录,避免交互输入密码,可以简单配置ssh互信来完成

192.168.2.9 本地主机       192.168.2.109 远程主机  

在2.9上执行的命令: 一路回车敲下去
[root@2.9 ~]# 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:
f6:51:47:62:dc:3f:d4:df:1e:85:87:96:7b:58:29:ea root@2.9


[root@2.9 ~]#  ssh root@192.168.2.109 "mkdir .ssh;chmod 0700 .ssh" 
root@192.168.2.109's password:(需要输入密码) 

[root@2.9 ~]# scp ~/.ssh/id_rsa.pub root@192.168.2.109:.ssh/id_rsa.pub 
root@192.168.2.109's password:(需要输入密码) 在2.109上的命令: 

[root@2.109~]# touch /root/.ssh/authorized_keys 
[root@2.109~]# <# cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys2 (将id_rsa.pub的内容追加到 authorized_keys 中) 

在2.9 ssh 登陆测试: # ssh root@192.168.2.109 (不需要密码, 登录成功)

抱歉!评论已关闭.