git ssh-keygen -t rsa -C“[email protected]

ssh-keygen -t rsa -C"[email protected]"

2018.07.17 15:17:44字数 424阅读 7576

1)在本地创建ssh key

打开终端,输入以下命令行

$ ssh-keygen -t rsa -C"[email protected]"

后面的[email protected]改为你的邮箱。我的邮箱是[email protected],也是在github上注册的那个邮箱:

直接点回车,说明会在默认文件id_rsa上生成ssh key。 

然后系统要求输入密码,直接按回车表示不设密码

重复密码时也是直接回车,之后提示你shh key已经生成成功。

git ssh-keygen -t rsa -C“your_email@youremail.com“_第1张图片

然后在终端输入:open ~/.ssh 回车即可打开对应生成的文件,如下图

打开id_rsa.pub,复制里面的key。里面的key是一对看不懂的字符数字组合,不用管它,直接复制。

Mac机可能没有对应程序打开,可以在终端输入 vim ~/.ssh/id_rsa.pub 打开该文件,如下图

复制内容即可,最后可以按下shift+Q,输入q!退出文件编辑状态即可

回到github网站,进入Account Settings,左边选择SSH Keys,Add SSH Key,

title随便填,粘贴key。

2)验证是否成功,在git bash下输入

$ ssh -T [email protected]

回车就会看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。

git ssh-keygen -t rsa -C“your_email@youremail.com“_第2张图片

3)接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们

$ git config --global user.name"your name"

$ git config --global user.email"[email protected]"

分别输入上述命令行 回车, 我的界面显示如下

git ssh-keygen -t rsa -C“your_email@youremail.com“_第3张图片

你可能感兴趣的:(linux,ssh,c语言,github)