0%

gitlab 中的 ssh 登录和远程仓库的更换

ssh登录的设置

生成 ssh 公钥和私钥

1
ssh-keygen -t rsa -C "you@email.com"

输入文件名,完成创建。

更改 ssh config

打开 ~/.ssh/config,添加如下的文件

1
2
3
4
5
Host your_host
HostName example.com
RSAAuthentication yes
IdentityFile ~/.ssh/your_rsa_file
User git

更改服务器的ssh设置

将你的公钥文件(后缀名为.pub)导入到服务器中(服务器会将其添加到 authorized_keys 文件中)

切换远程仓库

首先使用 git remote -v 找到自己原来的远程仓库,例如 github.com/phpcyy/first.git。 在自己的目录中输入以下命令完成换源

1
git remote set-url origin your_host:/phpcyy/first.git

从此之后使用 git 命令再也不用输入密码了