【Git】本地配置多个SSH

目录

问题

命令

参考


问题

最近远程办公,电脑里好多项目,每个SSH 都不一样,而且远程办公后,发现之前的都忘了,以前的土办法就是去机器上拷贝SSH 文件(xxx_id_rsa 和xxx_id_rsa.pub) 文件,现在这情况异地无法copy,没办法自己申请走流程再搞下;

汇总一些SSH 相关的命令,简单记录一下;

命令

生成ssh key

# 本地没有的话,使用如下
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

# 或者,指定文件名
$ ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/xxx_rsa

检查ssh 签名:

# SHA256
$ ssh-keygen -l -f github_id_rsa.pub

# MD5
$ ssh-keygen -E md5 -l -f github_id_rsa.pub

配置多个ssh key:

# 举例 github
Host github.com
  HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/github_id_rsa

# 举例 xxx
Host xxx.com
  HostName xxx.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/xxx_id_rsa

ssh-keygen 帮助命令:

usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa]
                  [-N new_passphrase] [-C comment] [-f output_keyfile]
       ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
       ssh-keygen -i [-m key_format] [-f input_keyfile]
       ssh-keygen -e [-m key_format] [-f input_keyfile]
       ssh-keygen -y [-f input_keyfile]
       ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
       ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]
       ssh-keygen -B [-f input_keyfile]
       ssh-keygen -D pkcs11
       ssh-keygen -F hostname [-f known_hosts_file] [-l]
       ssh-keygen -H [-f known_hosts_file]
       ssh-keygen -R hostname [-f known_hosts_file]
       ssh-keygen -r hostname [-f input_keyfile] [-g]
       ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]
       ssh-keygen -T output_file -f input_file [-v] [-a rounds] [-J num_lines]
                  [-j start_line] [-K checkpt] [-W generator]
       ssh-keygen -s ca_key -I certificate_identity [-h] [-U]
                  [-D pkcs11_provider] [-n principals] [-O option]
                  [-V validity_interval] [-z serial_number] file ...
       ssh-keygen -L [-f input_keyfile]
       ssh-keygen -A
       ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]
                  file ...
       ssh-keygen -Q -f krl_file file ...

参考

  1. https://help.github.com/cn
  2. 使用 SSH 连接到 GitHub
  3. 检查现有 SSH 密钥
  4. 生成新 SSH 密钥并添加到 ssh-agent

       (完)

发布了66 篇原创文章 · 获赞 17 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/DovSnier/article/details/104498357