一、首先安装git,注意,使用管理员权限(su)
# yum install git
二、然后,生成SSH key,下面命令中的“yourname@youremail.com"替换成github注册的邮箱
ssh-keygen -t rsa -b 4096 -C "yourname@youremail.com"
三次回车(如果希望使用密码,则在第二次第三次回车前输入密码,通常不用输入密码)。
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
系统会提示在/root/.ssh目录下生成了id_rsa.和is_rsa.pub两个文件,这就算存储密钥的私有及公有key文件。
三、将生成的SSH key添加到SSH-agent
Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key.
Start the ssh-agent in the background.
# eval "$(ssh-agent -s)"
> Agent pid 59566
Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.
$ ssh-add ~/.ssh/id_rsa
五、复制SSH key
vim或者cat,然后复制,或者利用linuxclip工具
Downloads and installs xclip. If you don’t have apt-get
, you might need to use another installer (like yum
)
$ yum install xclip
$ xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
下面就是去github网站,填写SSH key。
In the upper-right corner of any page, click your profile photo, then click Settings.
In the user settings sidebar, click SSH and GPG keys.
Click New SSH key or Add SSH key.
In the “Title” field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key “Personal MacBook Air”.
Paste your key into the “Key” field.
Click Add SSH key.
The Add key button
If prompted, confirm your GitHub password.