太久没用了,相当陌生,重新整理下做好记录。
个人习惯使用putty,所以只整理putty的。
测试环境是CENTOS6.2 64位。
首先在putty下用ssh-keygen命令生成公钥和私钥:
- [root@localhost ~]# 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:
- 5d:c7:10:e2:7b:a0:cb:19:18:e7:c5:cd:df:3a:9a:df root@localhost.localdomain
- The key's randomart image is:
- +--[ RSA 2048]----+
- | . o. |
- | o + o |
- | . . = + o |
- | = + + o . |
- | . S o . . .|
- | . + . . |
- | + o |
- | o o |
- | o.. E|
- +-----------------+
- [root@localhost ~]# ls .ssh/
- id_rsa id_rsa.pub
其中id_rsa是私钥,id_rsa.pub是公钥。
其中Enter passphrase提示输入密码,但是我要的就是免密码登陆,所以直接回车。
生成authorized_keys文件
- [root@localhost ~]# cp .ssh/id_rsa.pub .ssh/authorized_keys
- [root@localhost ~]# ls .ssh/
- authorized_keys id_rsa id_rsa.pub
将id_rsa文件拿到本地(为嘛putty没有securecrt直接上传下载文件的命令
),然后使用puttygen转换工具将私钥转换。
点击conversions——import key导入你拿到本地的私钥
点击save private key(红框标出的位置)。
修改服务器的配置:
- vi /etc/ssh/sshd_config
- PasswordAuthentication no (禁止密码登陆)
- ChallengeResponseAuthentication no (默认就是no 同上)
- AuthorizedKeysFile .ssh/authorized_keys (前面)
- [root@localhost ~]# /etc/init.d/sshd restart
- Stopping sshd: [ OK ]
- Starting sshd: [ OK ]
使用Putty登陆,不做更改登陆,出现如下报错:
修改Putty:
点击browse找到生成的private key,然后就能顺利登陆了。
- login as: root
- Authenticating with public key "imported-openssh-key"
- Last login: Tue Oct 30 10:45:33 2012 from 10.1.1.103
- [root@localhost ~]#
另外,将authorized_keys传到别的linux服务器上,也可以做到免密码登陆。
阅读(2129) | 评论(0) | 转发(0) |