您的位置:首页 > 运维架构 > Linux

ssh免密码登录

2016-02-18 16:08 459 查看
在linux上生成密钥对,并把公钥放到远程linux上,实现密钥验证登陆
假如您的两台linux分别为A和B,在A上执行:
[root@localhost ~]# ssh-keygen
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:
00:8f:00:7f:4c:21:8b:48:0b:3a:04:30:7c:32:3f:b2 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|X+o +.           |
|*B.B +           |
|=.B + o          |
| o +   .         |
|  o .   S        |
| E              |
|               |
|               |
|               |
+-----------------+

它在/home/chenlb下生成.ssh目录,.ssh下有id_rsa和id_rsa.pub。
cat  .ssh/id_rsa.pub
复制这些内容粘贴到B机器的 /root/.ssh/authorized_keys 文件里,此时B机器上若没有/root/.ssh 目录,则需要先创建,并修改其权限:
mkdir /root/.ssh
chmod 700 /root/.ssh
vi /root/.ssh/authorized_keys
authorized_keys的权限要是600。
chmod 600 .ssh/authorized_keys

.A机登录B机。
[chenlb@A ~]$ ssh 192.168.1.181
就可以登录到B机器上了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ssh centos 密钥