[配置Linux 免密码登陆](#配置Linux 免密码登陆)[1 生成秘钥对,一路回车就好](#<strong>1 生成秘钥对,一路回车就好</strong>)
[2 修改公钥名称为authorized_keys](#<strong>2 修改公钥名称为authorized_keys</strong>)
[3 修改权限为600](#<strong>3 修改权限为600</strong>)
[4 修改sshd配置文件](#<strong>4 修改sshd配置文件</strong>)
[5 重启sshd服务](#<strong>5 重启sshd服务</strong>)
配置Linux 免密码登陆
友情提示:如果需要实现xshell 等终端工具实现免密码登陆的,在生成密钥对的时候,务必先把id_rsa就拷贝出来,不然到时候你配置好了的时候,通过xftp等工具拷贝文件出来,发现本地没有密钥文件,到时候就是死循环了。切记切记!!
1 生成秘钥对,一路回车就好
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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:
92:98:a4:6d:a3:bf:04:67:f5:5f:d9:e2:9f:e1:b8:c1 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . . |
| + + o o |
| o O o S + . |
| * . . . + . |
| . . . E . |
| o = o |
| o. o.+ |
+-----------------+
[root@localhost ~]#
2 修改公钥名称为authorized_keys
[root@localhost .ssh]# cd /root/.ssh/
[root@localhost .ssh]# cat id_rsa.pub >authorized_keys
3 修改权限为600
[root@localhost .ssh]# chmod 600 authorized_keys
4 修改sshd配置文件
[root@localhost .ssh]# vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
5 重启sshd服务
[root@localhost .ssh]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[root@localhost .ssh]#
最后拷贝is_rsa 到任意地方保存即可实行无密码登陆