SSH的密匙管理, 免密码登录
2014-05-14 11:11
253 查看
ssh访问可以通过两种形式进行登录:
安全密码认证:登录username@remotehost,输入对应username的密码,该密码会被加密发给remotehost,接下来,remotehost会从密码数据库中进行匹配,如果成功,则登录成功。
密钥访问:localhost通过ssh-keygen来生成公钥密钥对,如果他想访问一个remotehost,则只需要将公钥添加到remotehost的~/.ssh/authorized_keys中,接下来,当localhost通过ssh登录username@remotehost时,remotehost会生成一个随机数,通过autrorized_keys中的公钥们生成一系列数值发给localhost,localhost会通过自己的私有密钥解密发过来的一系列数值(当然,只有用对应的公钥生成的数值才会被正常解密),随后,localhost将解密后的数值发回去,remotehost若发现发回来的数值是原先产生的随机数时,便会允许该localhost访问。当然,如果localhost生成的rsa密钥是需要密码的话,接下来还要输入该密码。
接下来,我就来举例如何通过ssh密钥实现自动访问。
配置localhost:如果还没有密钥公钥对生成,则先用ssh-keygen指令生成一个密钥对。
[xhtml] view
plaincopy
wenry@MyHome:~$ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/wenry/.ssh/id_rsa):
Created directory '/home/wenry/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/wenry/.ssh/id_rsa.
Your public key has been saved in /home/wenry/.ssh/id_rsa.pub.
The key fingerprint is:
0f:c5:e1:e9:b1:a4:f2:e0:ee:9f:0a:bc:c7:c8:c8:b9 wenry@MyHome
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| o o |
| B |
| = o |
| o S o |
| . . + o |
| . +oo. . . |
| + o+o . |
| E..o+oo |
+-----------------+
在输入ssh-keygen指令后,只需要连续输入三个回车键,就可以生成不需要密码的密钥公钥对了,从而实现自动访问。
配置remotehost:将localhost的id_rsa.pub内容附加到remotehost的/home/username/.ssh/authorized_keys中。
这样配置之后,就可以在localhost上ssh username@hostname,无需密码直接访问了。
安全密码认证:登录username@remotehost,输入对应username的密码,该密码会被加密发给remotehost,接下来,remotehost会从密码数据库中进行匹配,如果成功,则登录成功。
密钥访问:localhost通过ssh-keygen来生成公钥密钥对,如果他想访问一个remotehost,则只需要将公钥添加到remotehost的~/.ssh/authorized_keys中,接下来,当localhost通过ssh登录username@remotehost时,remotehost会生成一个随机数,通过autrorized_keys中的公钥们生成一系列数值发给localhost,localhost会通过自己的私有密钥解密发过来的一系列数值(当然,只有用对应的公钥生成的数值才会被正常解密),随后,localhost将解密后的数值发回去,remotehost若发现发回来的数值是原先产生的随机数时,便会允许该localhost访问。当然,如果localhost生成的rsa密钥是需要密码的话,接下来还要输入该密码。
接下来,我就来举例如何通过ssh密钥实现自动访问。
配置localhost:如果还没有密钥公钥对生成,则先用ssh-keygen指令生成一个密钥对。
[xhtml] view
plaincopy
wenry@MyHome:~$ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/wenry/.ssh/id_rsa):
Created directory '/home/wenry/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/wenry/.ssh/id_rsa.
Your public key has been saved in /home/wenry/.ssh/id_rsa.pub.
The key fingerprint is:
0f:c5:e1:e9:b1:a4:f2:e0:ee:9f:0a:bc:c7:c8:c8:b9 wenry@MyHome
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| o o |
| B |
| = o |
| o S o |
| . . + o |
| . +oo. . . |
| + o+o . |
| E..o+oo |
+-----------------+
在输入ssh-keygen指令后,只需要连续输入三个回车键,就可以生成不需要密码的密钥公钥对了,从而实现自动访问。
配置remotehost:将localhost的id_rsa.pub内容附加到remotehost的/home/username/.ssh/authorized_keys中。
这样配置之后,就可以在localhost上ssh username@hostname,无需密码直接访问了。
相关文章推荐
- 构建SSH远程登录管理-密码认证-免密登录
- SSH远程管理(用户登录控制及密码验证)
- Linux下实现SSH免密码登录和实现秘钥的管理、分发、部署SHELL脚本分享
- SSH 免密码登录与本地多 Key 管理
- SSH的密匙管理, 免密码登录
- Linux下实现SSH免密码登录和实现秘钥的管理、分发、部署SHELL脚本分享
- ssh远程登录时实现不输入密码
- 防暴力破戒ssh登录密码
- 使用ssh不输入密码登录到Linux
- 不用密码使用ssh管理远程linux服务器
- ssh无密码登录
- 购物网站20:用户/顾客action----用户列表---用户退出---用户管理---用户登录---用户注册---修改密码---发送邮件
- 内网ssh登录linux服务器过程中密码验证很慢的解决办法
- Linux系统管理实践(4):忘记登录密码或账号
- 服务器间通过ssh使用密钥对实现无密码登录solaris,redhat,linux
- 不输入密码自动通过SSH方式登录服务器
- Client免输密码登录SSH Server的一种方法
- 实现ssh无密码登录
- OpenSuSE的ssh无法使用密码登录问题的解决办法
- ssh免密码自动登录及相关问题解决