当前位置:   article > 正文

ssh免密码快速登录_ll@ll-virtual-machine:~/.ssh$ ssh-keygen -t rsa ge

ll@ll-virtual-machine:~/.ssh$ ssh-keygen -t rsa generating public/private rs

首先明确,从userA通过ssh免密码登录到userB

1、在userA终端输入命令:ssh-keygen -t rsa

一路回车后出现下列信息:

  1. wrf@wrf-virtual-machine:~$ ssh-keygen -t rsa
  2. Generating public/private rsa key pair.
  3. Enter file in which to save the key (/home/wrf/.ssh/id_rsa):
  4. Enter passphrase (empty for no passphrase):
  5. Enter same passphrase again:
  6. Your identification has been saved in /home/wrf/.ssh/id_rsa.
  7. Your public key has been saved in /home/wrf/.ssh/id_rsa.pub.
  8. The key fingerprint is:
  9. SHA256:uOWi24pciEx7zFrnQFaiZqcmNZe9dzkVNCJUOa9mplQ wrf@wrf-virtual-machine
  10. The key's randomart image is:
  11. +---[RSA 2048]----+
  12. | .o.o.o |
  13. | .oo . |
  14. | . . o. |
  15. | . oo . E .. |
  16. | =o+o o S. .. |
  17. |=oO+ =. =o |
  18. |o=.*..+.o=+ |
  19. |o.+o+o o.. . |
  20. | .o ++. |
  21. +----[SHA256]-----+

 此时进入.ssh目录会看到id_rsa.pub文件,说明密钥对已经生成

  1. wrf@wrf-virtual-machine:~/.ssh$ ll
  2. total 20
  3. drwx------ 2 wrf wrf 4096 121 09:58 ./
  4. drwxr-xr-x 30 wrf wrf 4096 119 11:49 ../
  5. -rw------- 1 wrf wrf 1679 121 09:58 id_rsa
  6. -rw-r--r-- 1 wrf wrf 405 121 09:58 id_rsa.pub
  7. -rw-r--r-- 1 wrf wrf 666 113 13:43 known_hosts

2、在userA终端输入命令:ssh-copy-id userB@192.168.1.112

注意:其中userB为有要登录的远端服务器@后面是远端服务器的ip地址

  1. wrf@wrf-virtual-machine:~$ ssh-copy-id nvidia@192.168.1.112
  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. nvidia@192.168.1.112's password:
  5. Number of key(s) added: 1
  6. Now try logging into the machine, with: "ssh 'nvidia@192.168.1.112'"
  7. and check to make sure that only the key(s) you wanted were added.

3、使用ssh登录userB,发现已经不用密码登录,进入.ssh文件夹可以看到id_rsa.pub文件已经被copy到userB的.ssh目录下

  1. nvidia@tegra-ubuntu:~$ ls -ll .ssh/
  2. total 16
  3. -rw------- 1 nvidia nvidia 2009 117 12:34 authorized_keys
  4. -rw------- 1 nvidia nvidia 1679 117 12:19 id_rsa
  5. -rw-r--r-- 1 nvidia nvidia 401 117 12:19 id_rsa.pub
  6. -rw-r--r-- 1 nvidia nvidia 444 117 12:13 known_hosts

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/497480
推荐阅读
相关标签
  

闽ICP备14008679号