生成SSH密钥(Linux)

生成SSH密钥(Linux

如果决定不使用推荐的HTTPS方式,可以使用SSH密钥连接电脑和GitHub。既然,知道GitHub那就可能已经在此网站上注册了自己的账号。

 

Step1: 检查SSH密钥

首先,打开终端,输入以下指令,查看是否已经生成SSH密钥。

 

cd ~/.ssh
ls
# Lists the files in your .ssh directory

在输入ls后,看看是否有文件 id_rsa.pub 或者 id_dsa.pub,或者两者皆有。如果已经存在这两个文件,则不需进行Step 2,之前如果输入了密码,可以直接跳过Step3

 

Step2: 生成新的SSH密钥

输入下面的第一条指令,指令中输入一个邮箱,会出现要你自己定义一个文件来保存Key,直接Enter通过。

ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/home/you/.ssh/id_rsa):

输入密码(不能少于4个,否则重输入)。

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

终端给出的信息如下,告诉Key的保存位置,后面需要用到。

# Your identification has been saved in /home/you/.ssh/id_rsa.
# Your public key has been saved in /home/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

Step3: 添加SSH KeyGitHub

运行下面这些指令:(打了#号的不用,)。

sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)
 
xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

 

进入网站GitHub,对以下进行设置:

1.      点击账户设置(很明显的,就在右上角);

2.      点击 "SSHKeys" 在左边;

3.      工作区出现

点击Add SSH key,出现下面。

4.      点击 "Add key"

5.      输入密码进行确认,这个密码就是在Step 3中输入的密码,这个弹出窗口会在输入

xclip -sel clip < ~/.ssh/id_rsa.pub

指令是出现。

Step4: 测试是否成功

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

输入上面的指令,而且指令中的git@github.com是不可以随意输的,一般就是这个,其实也就是这个。

可能出现的错误信息:

...
Agent admitted failure to sign using the key.
debug1: No more authentication methods to try.
Permission denied (publickey).

警告:

# The authenticity of host 'github.com (207.97.227.239)' can't be established.
# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
# Are you sure you want to continue connecting (yes/no)?

莫担心,没事的,输入yes,直接秒杀。

# Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.

成功的是:

 

If that username is correct, you've successfully set up your SSH key. Don't worry about the shell access thing, you don't want that anyway.

原英文文档:https://help.github.com/articles/generating-ssh-keys#platform-linux,其实英文文档中说的很明白了,直接跟着走就可以了,其实,很多东西看看最原始的本质,才可以对此理解的更好,掌握更加透彻。但是,为了方便自己和他人,还是弄了一下,方便今后查阅。对于Git的使用方法,也不是很明白,还需要在今后学习,积累,友情链接为:https://help.github.com/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值