您的位置:首页 > 编程语言

Github ssh key生成,免密登录服务器方法

2016-07-30 00:00 525 查看
摘要: github sshkey生成

个人博客地址:https://deepzz.com

生成sshkey

1、查看是否存在ssh key,如果有会列出key的列表

$ ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

2、没有,继续创建,下一步

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
Generating public/private rsa key pair.

3、使用默认配置,点击Enter,继续

Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

4、输入密码,可以为空,Enter。(如果有密码,以后每次使用到该key都会要求输入密码,非常的繁琐)

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

5、到这里,ssh key 创建完成

Your identification has been saved in /Users/you/.ssh/id_rsa.
Your public key has been saved in /Users/you/.ssh/id_rsa.pub.
The key fingerprint is:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

6、添加到ssh-agent。首先确定ssh-agent is enabled:

# start the ssh-agent in the background
$ eval "$(ssh-agent -s)"
Agent pid 59566

7、添加

$ ssh-add ~/.ssh/id_rsa

8、说明
id_rsa是私钥,id_rsa.pub是公钥。私钥是不能外泄的,我们需要用到的是公钥。
读取到公钥的内容,你就可以在github添加key了。

连接github

1、复制公钥

$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

2、将公钥粘贴到github的sshkey库里

3、测试连接

$ ssh -T git@github.com
# Attempts to ssh to GitHub

免密登录

1、你还可以将id_rsa.pub添加到ubuntu系统中,就可以远程免密登录了。

$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

保持长连接:ssh -o ServerAliveInterval=100 root@121.42.162.85 //每一百秒发空包保持连接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: