ssh key生成

来源:互联网 发布:程序员平均年薪40万 编辑:程序博客网 时间:2024/06/04 01:34

一,设置下git的用户名和邮箱

在提交代码前,还需要设置下git的用户名和邮箱(最好用英文,不要出现中文),这样提交记录才会在gitlab上显示带有你名字的记录。
git config --global user.name"your_name"
git config --global user.email "your_email"

二,在 gitlab 上添加 SSH key 的步骤


1,首先检查当前是否有SSH key:

cd ~/.ssh

cd ls -l

这两个命令就是检查是否已经存在 id_rsa.pub 或 id_dsa.pub 文件.

2、创建一个 SSH key 

$ ssh-keygen -t rsa -C "your_email@example.com"

代码参数含义:

-t 指定密钥类型,默认是 rsa ,可以省略。
-C 设置注释文字,比如邮箱。
-f 指定密钥文件存储文件名。

以上代码省略了 -f 参数,因此,运行上面那条命令后会让你输入一个文件名,用于保存刚才生成的 SSH key 代码,如:

Generating public/private rsa key pair.# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]

当然,你也可以不输入文件名,使用默认文件名(推荐),那么就会生成 id_rsa 和 id_rsa.pub 两个秘钥文件。

需要把ssh key添加到gitlab上去就可以

3、添加你的 SSH key 到 githab上面去

a、首先你需要拷贝 id_rsa.pub 文件的内容,你可以用编辑器打开文件复制,也可以用git命令复制该文件的内容,如:

$ clip < ~/.ssh/id_rsa.pub
或者
在目录下直接cat id_rsa.pub

4、测试一下该SSH key

$ ssh -T git@gitlab.com


如果提示:Welcome to GitLab, username! 

则表示已经是配置成功,如果还是不可以的话,那么需要在目录下配置config文件,

例如:

Host        gitlab
    HostName        gitlab.com
    Port            22
    IdentityFile    ~/.ssh/id_rsa

最后再重启下ubuntu就可以了



相关链接资料:

http://blog.csdn.net/w13770269691/article/details/38705473/

http://blog.csdn.net/huaishu/article/details/50475175

http://blog.csdn.net/u012314708/article/details/50428125

http://www.cnblogs.com/wutianlong/p/5465391.html

https://github.com/Yixiaohan/show-me-the-code




0 0
原创粉丝点击