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

本文详细介绍如何生成SSH Key,并提供了具体的步骤指导。从检查现有SSH Key开始,到创建新的SSH Key,再到添加公钥至GitHub及实现免密登录的过程都被清晰地阐述。此外,还介绍了如何在Ubuntu系统中添加公钥,实现远程免密登录。

个人博客地址: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 //每一百秒发空包保持连接

转载于:https://my.oschina.net/u/1466350/blog/724283

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值