1、安装git命令:
# yum install -y git
2、回到当前用户的家目录下
# cd ~
3、创建公钥和私钥对
# ssh-keygen -t rsa -C "github账号Email"
如果提示-bash ssh-keygen:command not found ,那么使用命令 # yum -y install openssh-clients安装openssh
4、接下来会有三个提示:
4.1 Enter file in which to save the key(/root/.ssh/id_rsd):
这个是提示你选择生成的秘钥保存路径。不填即为括号中的默认路径。
4.2 Enter passphrase(empty for no passphrase):
这是提示你输入一个密码,直接回车,即无密码,如果输入了密码,则在每次提交项目的时候都需要你在这里输入的这个密码,如果没有输入,则提交时不需要密码。
4.3 Enter same passphrase: 这个意思就是让你确认第二步中输入的密码,如果第二步没有输入密码,那么这一步直接回车即可。

5、使用cd命令打开.ssh目录,可以看到在.ssh目录下有3个文件:authorized_keys、id_rsa、id_rsa.pub,其中id_rsa是私钥,id_rsa_pub是公钥。
# cd .ssh
# ls -lla

6、登录你的github账户,点击你的头像,找到settings。

在跳转页面中找到SSH And GPG Keys,选择它。

然后再回到你的linux机器,打开id_rsa.pub文件,拷贝公钥。
# ls -lla
# cat id_rsa.pub

然后在回到github的SSH And GPG Keys,选择New SSH Key。

将你从linux机器上拷贝到的内容粘贴在Key文本框中,Title文本框,你可以随便填写。

接下来点击Add Key,要注意你只能用复制的方式,不能手动输入。
7、测试ssh key是否成功?
# ssh -T git@github.com

出现的交互式对话中选择yes,接下来如果出现You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
如果出现“Agent admitted failure to sign using the key.Permission denied (publickey).”这个错误的话,在命令行下执行
# ssh -add。
8、到此为止,你已经在你的linux机器上成功的连接上了你的github账户。
网友评论