ssh 无密码登录
2014-10-17 11:00
288 查看
也知道这个东西,大家都会,就当是谁忘了的时候,做个提醒的吧。。。
ssh 是一个专为远程登录会话和其他网络服务提供安全性的协议。默认状态下ssh链接是需要密码认证的,可以通过添加系统认证(即公钥-私钥)的修改,修改后系统间切换可以避免密码输入和ssh认证。以下将创建过程简单介绍下。
一、用ssh-keygen创建公钥
haifeng@haifeng-EX38-DS4:/$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/haifeng/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/haifeng/.ssh/id_rsa.
Your public key has been saved in /home/haifeng/.ssh/id_rsa.pub.
The key fingerprint is:
7b:75:98:eb:fd:13:ce:0f:c4:cf:2c:65:cc:73:70:53 haifeng@haifeng-EX38-DS4
The key's randomart image is:
+--[ RSA 2048]----+
| E|
| .|
| ...|
| + =.|
| S + +.*|
| . . + Bo|
| . . . = =|
| . . . * |
| . ..=|
+-----------------+
##输入后,会提示创建.ssh/id_rsa、id_rsa.pub的文件,其中第一个为密钥,第二个为公钥。过程中会要求输入密码,为了ssh访问过程无须密码,可以直接回车 。
2.查看钥匙。
[root@localhost .ssh]# ls ~/.ssh/
id_rsa id_rsa.pub known_hosts
###可以发现 ssh目录下的两枚钥匙。
3.将公钥复制到被管理机器上面
[root@localhost .ssh]# scp id_rsa.pub root@192.168.36.194:~/.ssh/authorized_keys
root@192.168.36.194's password:
id_rsa.pub 100% 408 0.4KB/s 00:00
4.访问
#
ssh 192.168.36.194
The authenticity of host '<Game2> (<192.168.36.194>)' can't be established.
RSA key fingerprint is 34:b9:92:06:53:e6:91:4d:47:92:73:57:78:6a:5d:09.
Are you sure you want to continue connecting (yes/no)?yes
Warning: Permanently added '<Game2>
(<192.168.36.194>'
(RSA) to the list of known hosts.
这是因为首次访问后,ssh会在.ssh/known_hosts中保存各个认证过的主机信息:
192.168.36.194 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAppStzIRxeFn0e737z7KO1tdm6CJUoLapaaoBDZqHy0Z11cUAmpg02dbrqwU7TBY9lDFwWQcry+W8X8qk1CoPdzu8YcMCpw5425mai0/RxkB/RPZ1putL2DQrRBMRTU1m5meLOYRXYlnU5E+YElCgH+ZJ8EXiurOzDvw6vi7pASi9wMQuJosFyNmv5E9/8ULgaKg3LtvP+0O1wPxrHOBDwVq2u9Oi7T2pX8deBEnOI4uG4CGXn/p0ml+uuS4DO3Up2VjqoRtqtuzWExnTyAGS/wQNnN3mera1ERya3FomEVHJRV5K2zJRkgSF8WfETXzQ2rAliOsW/YLTGF8vVvjo5w==
5.再次访问,ssh登录发现可以不用密码登录。
[root@localhost .ssh]# ssh 192.168.36.194
Last login: Fri Apr 22 00:56:45 2011 from 192.168.18.44
可能遇到的问题:
1.进行ssh登录时,出现:”Agent admitted failure to sign using the key“ .
执行: $ssh-add
强行将私钥 加进来。
2.如果无任何错误提示,可以输密码登录,但就是不能无密码登录,在被连接的主机上(如A向B发起ssh连接,则在B上)执行以下几步:
$chmod o-w ~/
$ps -Af | grep agent
检查ssh代理是否开启,如果有开启的话,kill掉该代理,然后执行下面,重新打开一个ssh代理,如果没有开启,直接执行下面:
$ssh-agent
还是不行的话,执行下面,重启一下ssh服务
$sudo service sshd restart
4. 执行ssh-add时提示“Could not open a connection to your authenticationh agent”而失败
执行: ssh-agent bash
ssh 是一个专为远程登录会话和其他网络服务提供安全性的协议。默认状态下ssh链接是需要密码认证的,可以通过添加系统认证(即公钥-私钥)的修改,修改后系统间切换可以避免密码输入和ssh认证。以下将创建过程简单介绍下。
一、用ssh-keygen创建公钥
haifeng@haifeng-EX38-DS4:/$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/haifeng/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/haifeng/.ssh/id_rsa.
Your public key has been saved in /home/haifeng/.ssh/id_rsa.pub.
The key fingerprint is:
7b:75:98:eb:fd:13:ce:0f:c4:cf:2c:65:cc:73:70:53 haifeng@haifeng-EX38-DS4
The key's randomart image is:
+--[ RSA 2048]----+
| E|
| .|
| ...|
| + =.|
| S + +.*|
| . . + Bo|
| . . . = =|
| . . . * |
| . ..=|
+-----------------+
##输入后,会提示创建.ssh/id_rsa、id_rsa.pub的文件,其中第一个为密钥,第二个为公钥。过程中会要求输入密码,为了ssh访问过程无须密码,可以直接回车 。
2.查看钥匙。
[root@localhost .ssh]# ls ~/.ssh/
id_rsa id_rsa.pub known_hosts
###可以发现 ssh目录下的两枚钥匙。
3.将公钥复制到被管理机器上面
[root@localhost .ssh]# scp id_rsa.pub root@192.168.36.194:~/.ssh/authorized_keys
root@192.168.36.194's password:
id_rsa.pub 100% 408 0.4KB/s 00:00
4.访问
#
ssh 192.168.36.194
The authenticity of host '<Game2> (<192.168.36.194>)' can't be established.
RSA key fingerprint is 34:b9:92:06:53:e6:91:4d:47:92:73:57:78:6a:5d:09.
Are you sure you want to continue connecting (yes/no)?yes
Warning: Permanently added '<Game2>
(<192.168.36.194>'
(RSA) to the list of known hosts.
这是因为首次访问后,ssh会在.ssh/known_hosts中保存各个认证过的主机信息:
192.168.36.194 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAppStzIRxeFn0e737z7KO1tdm6CJUoLapaaoBDZqHy0Z11cUAmpg02dbrqwU7TBY9lDFwWQcry+W8X8qk1CoPdzu8YcMCpw5425mai0/RxkB/RPZ1putL2DQrRBMRTU1m5meLOYRXYlnU5E+YElCgH+ZJ8EXiurOzDvw6vi7pASi9wMQuJosFyNmv5E9/8ULgaKg3LtvP+0O1wPxrHOBDwVq2u9Oi7T2pX8deBEnOI4uG4CGXn/p0ml+uuS4DO3Up2VjqoRtqtuzWExnTyAGS/wQNnN3mera1ERya3FomEVHJRV5K2zJRkgSF8WfETXzQ2rAliOsW/YLTGF8vVvjo5w==
5.再次访问,ssh登录发现可以不用密码登录。
[root@localhost .ssh]# ssh 192.168.36.194
Last login: Fri Apr 22 00:56:45 2011 from 192.168.18.44
可能遇到的问题:
1.进行ssh登录时,出现:”Agent admitted failure to sign using the key“ .
执行: $ssh-add
强行将私钥 加进来。
2.如果无任何错误提示,可以输密码登录,但就是不能无密码登录,在被连接的主机上(如A向B发起ssh连接,则在B上)执行以下几步:
$chmod o-w ~/
$chmod 700 ~/.ssh
$chmod 600 ~/.ssh/authorized_keys
必须是以上两种权限,700,600. 3.如果执行了第2步,还是不能无密码登录,再试试下面几个
$ps -Af | grep agent
检查ssh代理是否开启,如果有开启的话,kill掉该代理,然后执行下面,重新打开一个ssh代理,如果没有开启,直接执行下面:
$ssh-agent
还是不行的话,执行下面,重启一下ssh服务
$sudo service sshd restart
4. 执行ssh-add时提示“Could not open a connection to your authenticationh agent”而失败
执行: ssh-agent bash
相关文章推荐
- CentOS 6.0下SSH免密码登录配置
- ssh免密码登录
- CentOS 7 下不同主机间 ssh 免密码登录
- ssh 免密码登录
- SSH免密码登录
- ssh 免密码登录 密钥登录
- ssh免密码登录另外一个主机
- 使用ssh-keygen设置ssh无密码登录
- 设置ssh不输入密码登录远端SSH服务器
- ssh免密码登录
- CentOS配置SSH免密码登录
- ssh免密码登录
- 阿里云主机ssh 免密码登录
- ssh 免密码登录linux
- centos6.5配置SSH免密码登录
- SSH登录等待输入密码太慢
- SSH无密码登录
- ssh无需密码提示登录
- Xshell配置ssh免密码登录-密钥公钥(Public key)与私钥(Private Key)登录【已成功实例】
- 在CentOS/RHEL上设置SSH免密码登录