使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录

分手后的思念是犯贱 2022-07-21 05:49 263阅读 0赞

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

ssh-copy-id 将本机的公钥复制到远程机器的authorized_keys文件中,ssh-copy-id也能让你有到远程机器的home, ~./ssh , 和 ~/.ssh/authorized_keys的权利

第一步:在本地机器上使用ssh-keygen产生公钥私钥对

  1. jsmith@local-host$ [Note: You are on local-host here]
  2. jsmith@local-host$ ssh-keygen
  3. Generating public/private rsa key pair.
  4. Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
  5. Enter passphrase (empty for no passphrase): [Press enter key]
  6. Enter same passphrase again: [Pess enter key]
  7. Your identification has been saved in /home/jsmith/.ssh/id_rsa.
  8. Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
  9. The key fingerprint is:
  10. 33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host

第二步:用ssh-copy-id将公钥复制到远程机器中

  1. jsmith@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
  2. jsmith@remote-host’s password:
  3. Now try logging into the machine, with “ssh ‘remote-host’”, and check in:
  4. .ssh/authorized_keys
  5. to make sure we haven’t added extra keys that you weren’t expecting.

注意: ssh-copy-id 将key写到远程机器的 ~/ .ssh/authorized_key.文件中

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

  1. jsmith@local-host$ ssh remote-host
  2. Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
  3. [Note: SSH did not ask for password.]
  4. jsmith@remote-host$ [Note: You are on remote-host here]

另外:

  1. ssh-copy-id -u wyz -i ~/.ssh/id_rsa.pub wyz@remote_host

上述是给wyz用户赋予无密码登陆的权利

发表评论

表情:
评论列表 (有 0 条评论,263人围观)

还没有评论,来说两句吧...

相关阅读

    相关 linux ssh密码登录

    使用一种被称为"公私钥"认证的方式来进行ssh登录. "公私钥"认证方式简单的解释:首先在客户端上创建一对公私钥 (公钥文件:~/.ssh/id\_rsa.pub; 私钥文件:

    相关 实现ssh密码登录

    这里所说的ssh是指OpenSSH SSH客户端,是用于登录远程主机,并且在远程主机上执行命令。它的目的是替换rlogin和rsh,同时在不安全的网络之上,两个互不信任的主机之

    相关 SSH 密码登录 Linux

    SSH Key的知识 Linux系统有一个钥匙环(keyring)的管理程序.钥匙环受到用户登录密码的保护.当你登录Linux系统时,会自动解开钥匙环的密码,从而可访问钥