Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
privking committed Aug 16, 2021
1 parent 446c8aa commit a7623c6
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions linux/13git配置ssh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# git配置ssh

**确认已经存在的ssh key**

windows在gitbash中执行

```sh
ls -al ~/.ssh
```

**如果没有,生成新的ssh key 并添加到ssh-agent**

生成ssh-key

```sh
ssh-keygen -t rsa -b 4096 -C "[email protected]"
#Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] 回车存放在默认地址

#Enter passphrase (empty for no passphrase): [Type a passphrase]
#Enter same passphrase again: [Type passphrase again]
#为ssh-key设置密码 在添加到ssh-agent时需要输入
```

私钥添加到ssh-agent

1.保证ssh-agent启用 返回经称id

```sh
eval "$(ssh-agent -s)"
```

2.把ssh key添加到ssh-agent中

```sh
ssh-add ~/.ssh/id_rsa # ~/.ssh/id_rsa 为默认存放地址
```

**在github中添加ssh key公钥**

```sh
~/.ssh/id_rsa.pub # 公钥地址
C:\Users\58443\.ssh # windows中对应路径
```

settings->ssh and gpg keys -> new ssh key

**测试连接**

```sh
ssh -T [email protected]
#The authenticity of host 'github.com (20.205.243.166)' can't be established.
#RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
#Are you sure you want to continue connecting (yes/no/[fingerprint])?
# yes
#Warning: Permanently added 'github.com,20.205.243.166' (RSA) to the list of known hosts.
#Hi privking! You've successfully authenticated, but GitHub does not provide shell access.
```

**更改远程仓库url为ssh**

查看拥有的远程仓库:

```ssh
git remote -v
```

更改远程仓库的url:

```ssh
git remote set-url origin [email protected]:privking/king-note.git
```

查看是否修改成功

```ssh
git remote -v
```

**end**

0 comments on commit a7623c6

Please sign in to comment.