首页 > 编程知识 正文

git重新生成密钥,linux生成ssh密钥

时间:2023-05-04 16:26:26 阅读:243947 作者:3297

生成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 Key到GitHub

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

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.点击账户设置(很明显的,就在右上角);

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,直接秒杀。

# Hiusername! 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/。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。