git-ssh-config.md

设置SSh

使用SSH密钥在本地电脑和Git服务器之间建立安全连接

(1)检查是否已有SSH key

输入以下命令:

$ cd ~/.ssh

如果提示“No such file or directory“,则跳转到第3步,如果不是则继续第2步。

(2)备份并删除已有的SSH key
$ ls
Lists all the subdirectories in the current directory
config id_rsa id_rsa.pub known_hosts
$ mkdir key_backup
makes a subdirectory called "key_backup" in the current directory
$ cp id_rsa* key_backup
Copies the id_rsa and id_rsa.pub files into key_backup
$ rm id_rsa*

注意,以上只有美元符号后面才是你要在命令行中输入的命令,其它是对该命令的解释说明,或者输入命令后返回的结果。

(3)创建一个新的SSH key
$ ssh-keygen -t rsa -C "your_email@youremail.com"
Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<press enter>

首先注意,your_email@youremail.com这里要用你自己的邮箱地址,可别真的复制粘贴这个命令,那就有点2B了。
然后会提示输入passphrase(密码):
Enter passphrase(empty for no passphrase):<输入你的密码>
Enter same passphrase again:<再次输入你的密码>

(4) 将SSH key添加到Git服务器中

在Git服务器中点击Profile Settings,然后点击SSH Keys<,点击Add SSH Key,参考下图:

gitlab添加ssh key

使用文本编辑器打开id_rsa.pub文件。就会显示你的公共SSH密钥。
然后把它复制到”Key”字段中

(5) 设置信息

现在Git已经设置完毕,也输入了SSH Key,就可以配置个人信息了。

设置用户名和email

$ git config --global user.name "Firstname Lastname"
Sets the name of the user for all git instances on the system
$ git config --global user.email your_email@youremail.com

需要注意的是,这里的name是你的真名,不是Git的注册账号。

到这里,Git的设置工作就圆满了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值