前言

本教材适用于gitlab 和GitHub。

I 免密码进行SSH连接

  1. 创建rsa:​​ssh-keygen -t rsa -b 4096 -C "929118967@" ​
  2. 配置config:​​➜ .ssh touch config​
  3. 使用pbcopy或者ssh-copy-id进行拷贝公钥到对应的远程服务器

​➜ .ssh pbcopy < ~/.ssh/qctmac_id_rsa.pub​

程序员必备小知识:免密码进行SSH连接_.net

使用ssh-copy-id进行报备

ssh-copy-id:千万不要把私钥泄漏!只是把公钥(*.pub 文件)复制给远程服务器;

`$ ssh-copy-id -i ~/.ssh/id_rsa_Theos125 ​​root@192.168.2.144​

`(IP+默认端口 这里拷贝的是公钥,,如果是指定私钥ssh-copy-id 会自己寻找公钥。)

如果是配置在公司Mac上,记得设置密码,并在更换Mac时移除掉 ~/.ssh/ 目录下的​​xx_id_rsa/xx_id_rsa.pub​​。

1.1 创建 rsa

​ssh-keygen -t rsa -b 4096 -C "929118967@" ​

1.2 配置 ssh config

config文件的 语法

Host  别名
HostName: 是目标主机的主机名,也就是平时我们使用ssh后面跟的地址名称。
Port:指定的端口号。
User:指定的登陆用户名。
IdentifyFile:指定的私钥地址。
# Private 192.168.2.125
Host iphone
HostName 192.168.2.125
User root
IdentityFile ~/.ssh/id_rsa_Theos125

# Private github
Host
HostName
User git
IdentityFile ~/.ssh/id_rsa


Host
HostName
User git
IdentityFile ~/.ssh/qctmac_id_rsa

1.3 测试连接

➜  csdn ssh -T git@
Enter passphrase for key '/Users/mac/.ssh/qctmac_id_rsa':
Welcome to GitLab, @u011018979!

连接iPhone

$ ssh iPhone
root@192.168.2.125's password:
iPhone:~ root#

1.4 案例: 配置GitHub SSH keys

Enter ls -al ~/.ssh to see if existing SSH keys are present:

​If you don't have an existing public and private key pair, or don't wish to use any that are available to connect to GitHub, then generate a new SSH key.​

​ssh-keygen -t rsa -b 4096 -C "929118967@" ​

添加对应的公钥到对应的远程服务器:​​ .ssh pbcopy < ~/.ssh/qctmac_id_rsa.pub​

配置邮箱和用户名: ​​ git config --global --edit​

程序员必备小知识:免密码进行SSH连接_GitHub_02

修改 author :​​ git commit --amend --reset-author​

效果


II see also

​使用ssh config配置文件来管理ssh连接​

更多内容请关注​​#小程序:iOS逆向​​,只为你呈现有价值的信息,专注于移动端技术研究领域。