ssh免密登录

 

 

******配置主机之间的免密ssh登陆
假如 A  要登陆  B
在A上操作:
%%首先生成密钥对
ssh-keygen   (提示时,直接回车即可)
%%再将A自己的公钥拷贝并追加到B的授权列表文件authorized_keys中
ssh-copy-id   B

制作服务器linux1的密钥

[root@Linux1 .ssh]# 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:
SHA256:zRN+gLUHAfuxhfqzXVmv+CR5nHkW57B/9j1TnAszGEQ root@Linux1
The key's randomart image is:
+---[RSA 2048]----+
|        ..=E     |
|         + =     |
|        o B o    |
|         * O     |
|        S B + .o+|
|         . + * X*|
|          o o & B|
|           + * O+|
|          . o.o.O|
+----[SHA256]-----+
[root@Linux1 .ssh]# ll
总用量 12
//前两个为此操作新增的密钥,id_rsa.pub为公钥,id_rsa为私钥,公钥需要拷贝给别的服务器 
-rw-------. 1 root root 1675 7月  25 20:38 id_rsa
-rw-r--r--. 1 root root  393 7月  25 20:38 id_rsa.pub
-rw-r--r--. 1 root root  180 7月  25 20:26 known_hosts

将公钥复制到另一台服务器linux2 

[root@Linux1 ~]# ssh-copy-id linux2
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@linux2's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'linux2'"
and check to make sure that only the key(s) you wanted were added.

[root@Linux1 ~]#


//目标服务器中则出现authorized_keys授权公钥
[root@Linux2 .ssh]# ll
总用量 8
-rw-------. 1 root root 393 7月  24 13:02 authorized_keys
-rw-r--r--. 1 root root 180 7月  24 12:27 known_hosts

配置完成,linux1 可以免密登录 linux2

[root@Linux1 ~]# ssh linux2
Last login: Tue Jul 24 12:53:48 2018 from linux1.shared
[root@Linux2 ~]# exit

自己登录自己,即在 linux1免密登录linux1

[root@Linux1 ~]# ssh-copy-id linux1
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@linux1's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'linux1'"
and check to make sure that only the key(s) you wanted were added.

[root@Linux1 ~]#

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值