3步简单实现SSH无密码登录

下面简单的做下实验:

 

一:准备2台服务器:

1  192.168.10.101

2  192.168.10.102

 

二:关键字解释

ssh-keygen :  产生公钥与私钥对

ssh-copy-id :将本机的公钥复制到远程机器的authorized_keys文件中

 

三:开始实验

第一步: 在192.168.10.101上使用ssh-keygen产生公钥私钥对

 1 [root@controlm ~]# ssh-keygen 
 2 Generating public/private rsa key pair.
 3 Enter file in which to save the key (/root/.ssh/id_rsa): 
 4 Enter passphrase (empty for no passphrase): 
 5 Enter same passphrase again: 
 6 Your identification has been saved in /root/.ssh/id_rsa.
 7 Your public key has been saved in /root/.ssh/id_rsa.pub.
 8 The key fingerprint is:
 9 a4:ae:78:72:cc:94:34:2f:33:3f:a5:e5:20:51:d2:6c root@controlm
10 The key's randomart image is:
11 +--[ RSA 2048]----+
12 |     o           |
13 |    . E          |
14 |     +  .        |
15 |    +  o         |
16 |   . =. S        |
17 |    B.o o        |
18 |   + *.*         |
19 |  ..=.+ .        |
20 |  .+.  .         |
21 +-----------------+

第二步:用ssh-copy-id将公钥复制到远程机器1922.168.10.102中(注意::ssh-copy-id 是将key写到远程机器的 ~/ .ssh/authorized_key.文件中)

1 [root@controlm ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.10.102
2 /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
3 /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
4 root@192.168.10.102's password:   这里输入你的登录密码
5 
6 Number of key(s) added: 1
7 
8 Now try logging into the machine, with:   "ssh '192.168.10.102'"
9 and check to make sure that only the key(s) you wanted were added.

第三部: 登录到远程机器192.168.10.102不用输入密码

1 [root@controlm ~]# ssh 192.168.10.102
2 Last login: Wed Feb 27 11:32:23 2019 from 192.168.10.101
3 [root@docker ~]# 

 

转载于:https://www.cnblogs.com/zhoul/p/10443929.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值