码迷,mamicode.com
首页 > 其他好文 > 详细

ssh登录基于key验证

时间:2021-05-23 22:59:40      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:word   hostname   sed   scp   ssh   code   connect   nec   auth   

ssh基于key验证

1,在客户端生成公钥私钥对并将公钥拷到要连接的服务器上,验证是否成功
[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:
SHA256:vpPtmqRv1llmoSvqT2Lx5C0LPGTE0pvdAqhDqlR5jLY root@centos8.wangxiaochun.com
The key‘s randomart image is:
[root@localhost ~]# ll .ssh/
total 12
-rw-------. 1 root root 2610 May  3 13:11 id_rsa
-rw-r--r--. 1 root root  580 May  3 13:11 id_rsa.pub
[root@localhost ~]# ssh-copy-id root@10.1.1.3 #将公钥拷贝到服务器
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host ‘10.1.1.3 (10.1.1.3)‘ can‘t be established.
ECDSA key fingerprint is SHA256:KF7vnOMUbBsOJ17D/CI53zlfLpdetc7x93cZ4TMD/1E.
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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@10.1.1.3‘s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh ‘root@10.1.1.3‘"
and check to make sure that only the key(s) you wanted were added.
[root@localhost ~]# ssh 10.1.1.3 #验证成功
Last login: Mon May  3 10:35:46 2021 from 10.1.1.1
[root@route1 ~]# hostname -I
192.168.17.136 192.168.17.138 172.16.0.200 10.1.1.3 
[root@route1 ~]# exit
logout
Connection to 10.1.1.3 closed.
[root@localhost ~]# scp /etc/fstab 10.1.1.3:/root/
fstab                                                                                                            100%  615   403.3KB/s   00:00    

ssh登录基于key验证

标签:word   hostname   sed   scp   ssh   code   connect   nec   auth   

原文地址:https://www.cnblogs.com/catastrophe/p/14727377.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!