Skip to content

Instantly share code, notes, and snippets.

@iguoli
Last active September 13, 2018 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iguoli/a84588c870e3464448fafcc08504834e to your computer and use it in GitHub Desktop.
Save iguoli/a84588c870e3464448fafcc08504834e to your computer and use it in GitHub Desktop.
SSH Config配置及证书登录,ssh, ssh-keygen, putty, PuTTYgen

Linux下使用SSH免密登录

$ ssh-keygen -t rsa -C "yourname@youremail.com"

完成后会在~/.ssh下生成id_rsa(私钥)和id_rsa.pub(公钥)两个文件,将公钥内容加入目标主机的~/.ssh/authorized_keys文件内

$ ssh-copy-id user@host
#
$ scp .ssh/id_rsa.pub user@host:.ssh/authorized_keys
#
$ ssh user@host 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

之后就可以通过ssh user@host直接登录 目标主机。如果还是不行,就打开远程主机的/etc/ssh/sshd_config这个文件,检查下面几行前面"#"注释是否取掉。

  • RSAAuthentication yes
  • PubkeyAuthentication yes
  • AuthorizedKeysFile .ssh/authorized_keys

使用PuTTY免密登录

  1. 打开PuTTYgen
  2. 点击Generate按钮,然后晃动鼠标直到生成密钥
  3. 点击Save public key和Save private key保存公钥和私钥
  4. 将公钥内容复制到目标主机的~/.ssh/authorized_keys文件中
  5. 打开PuTTY,在SSH->Auth里将生成私钥添加进去

使用openssl将有密码密钥转换为无密码密钥

$ openssl rsa -in id_rsa -out id_rsa.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment