openssh

密钥登录原理:
就是用户将自己的公钥储存在远程主机上。登录的时候,远程主机会向用户发送一段随机字符串,用户用自己的私钥加密后,再发回来。远程主机用事先储存的公钥进行解密,如果成功,就证明用户是可信的,直接允许登录shell,不再要求输入密码,这和之前的ssh账号密码也没有直接关系。
这种方法要求用户必须提供自己的公钥。如果没有现成的,可以直接用ssh-keygen生成一个:

[root@localhost ~]# hostnamectl set-hostname server
[root@localhost ~]# bash
[root@server ~]# systemctl stop firewalld.service 
[root@server ~]# setenforce 0
[root@localhost ~]# hostnamectl set-hostname client
[root@localhost ~]# bash
[root@client ~]# systemctl stop firewalld
[root@client ~]# setenforce 0
setenforce: SELinux is disabled


用ssh-keygen生成一个密钥

[root@server ~]# 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:
SHA256:fIsT/cKWHprpZs0fHOendxI+2ih5LXhXf8aatcKy1xg root@server
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|                 |
|       . .       |
|        S o . .  |
|         = = E. .|
|        ooBo=o=++|
|        oB*++O**O|
|       += .*B+*Bo|
+----[SHA256]-----+

将公钥复制到远程系统的正确位置,要输密码登录

[root@client ~]# ssh-copy-id root@192.168.118.100
The authenticity of host '192.168.118.100 (192.168.118.100)' can't be established.
ECDSA key fingerprint is 1b:c1:f1:4b:50:42:c3:03:e3:1c:f6:4f:5a:3b:74:52.
Are you sure you want to continue connecting (yes/no)? yes
/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@192.168.118.100's password: 

Number of key(s) added: 1

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

再次ssh目标主机,实现免密登录

[root@server ~]# ssh root@192.168.118.128
Last login: Tue Aug 28 20:19:52 2018 from 192.168.118.1
[root@client ~]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值