SSH免密登陆 配置方法(Mac、Win)

非常简单,共以下三个步骤:

1. 电脑本地生成密钥

# 1. 电脑本地使用终端命令生成密钥(一路回车、用默认选项即可)
ssh-keygen -t rsa

2. 复制所生成的SSH公钥(.pub文件内容)

# 2. 使用终端命令行复制所生成的SSH公钥
cat ~/.ssh/id_rsa.pub | clip    # Windows
cat ~/.ssh/id_rsa.pub | pbcopy  # MacOS

3. 添加公钥到对应git仓安全设置中

 多人共用一个Linux机器时怎么配置SSH?

1. 每个人均生成属于自己的一对SSH密钥,使用-f参数指定生成的密钥文件位置

$ ssh-keygen -t rsa -f ~/.ssh/id_rsa.个人名字

2. 在 ~/.ssh/config 中指定各个用户的密钥地址

注意 ~/.ssh/config 文件的权限必须是644

chmod 644 ~/.ssh/config

文件内容(示例):

Host xxxx.baidu.com(代码仓地址)
User username1
IdentityFile ~/.ssh/id_rsa.username1

Host xxxx.baidu.com(代码仓地址)
User username2
IdentityFile ~/.ssh/id_rsa.username2

## 注意:username根据实际情况填写
## 这样完成后,当git clone ssh://[email protected] 就会 ~/.ssh/id_rsa.username1 来认证

3. 把自己的SSH公钥(.pub文件内容)贴到对应平台上即可

猜你喜欢

转载自blog.csdn.net/qq_52057693/article/details/127931187