使用git做为版本维护工具很是方便,并且通常我的用github做为远端库就够用了。而通常git链接github的方式采用ssh的方法,http的会略微慢一些。因此为了方便通常会在github设置中添加经常使用电脑的SSH公钥。python
首先确认是否安装了ssh工具:git
[yu@yu learn]$ ssh usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [user@]hostname [command]
如上证实ssh工具已安装。如未安装则使用yum或apt-get安装ssh:github
sudo yum -y install openssh-server openssh-clients sudo apt-git install ssh
确保安装ssh后执行以下命令生成RSA:shell
[yu@yu learn]$ ssh-keygen -t rsa -C "my_email@email.com" Generating public/private rsa key pair. Enter file in which to save the key (/home/yu/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/yu/.ssh/id_rsa. Your public key has been saved in /home/yu/.ssh/id_rsa.pub. The key fingerprint is: SHA256:hAIHR1Cc2hQo4GqcTI0vjz+vSI9biOyJ7MAgATE63gQ 312875237@qq.com The key's randomart image is: +---[RSA 2048]----+ |*E+B*o | |=.=++ . | |+= *. . . | |*o* .. . | |+B o S | |B = | |o* o | |* B. | |oO.++. | +----[SHA256]-----+
生成的RSA在用户家目录下的.ssh文件夹的id_rsa.pub文件中:dom
[yu@yu learn]$ cat /home/yu/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDC8lT8NWMOwPIlgXGaRpXcDuifDZ2llWLREgieBK6ncws9RawA/6vcg+wQ+GhtLARuK22GDALqAbiA66twoqa85El3Eb+nRyShm2gAOE+XwJCj9C7soMUxHREhoa4ZPrI4q8YjdRiv7j4IH+8D3J1wCYCxwCvt+YaNQ5WolmMEe6zDbzNOvCuudDZXKcpLfel9NDpRN3L5Y/xqciXS2Rgz611x3/acllm3zkVYv1LMg9Mybnos/+jIFv3dZZd2inJIEq+Qmp/4iMvO3vDu2bX3jJvlW/T+HEZeMiDIv/O4Khh3NRBOu82dcWAltcWyKOyuaHaDFqzvQaopwh37TI5P 3189109768@qq.com
进入github主页登录帐号,并进入Setting页面。切换到SSH and GPG keys选项卡,在SSH keys区域使用New SSH key 添加SSH公钥。ssh
其中,Title名称随意,最好有明确意义;Key处输入id_rsa.pub的内容。ide
使用ssh命令测试ssh登录,出现如下效果则表示登录成功。工具
[yu@yu learn]$ ssh -T git@github.com Hi treesYU! You've successfully authenticated, but GitHub does not provide shell access.