当前位置:   article > 正文

Linux生成密钥对并配置免密访问

Linux生成密钥对并配置免密访问

(1) 在客服端生成密钥对

先生成私钥,再生成公钥

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:
11:c5:3a:1a:ad:ff:d2:48:f8:ac:d4:62:67:38:8a:5f root@xx
The key's randomart image is:
+--[ RSA 2048]----+
|        .o.      |
|         ..      |
|       ...       |
|      . +.       |
|       =S.       |
|      +o.        |
|      E=+o       |
|   . = =* .      |
|  ..o .. o.      |
+-----------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

(2) 将公钥推送给服务端

方法一:
在服务端新建用户的存放公钥目录

mkdir  /home/u02/.ssh/  && chmod 700 /home/u02/.ssh/
  • 1
scp /root/.ssh/id_rsa.pub  u02@192.168.0.2:/home/u02/.ssh/authorized_key
  • 1

你需要远程主机那个用户,你就把公钥推送给那个用户 $HOME/.ssh/authorized_keys

方法二:
ssh-copy-id --只能使用默认端口22

ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.0.2
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/553717
推荐阅读
相关标签
  

闽ICP备14008679号