本地虚拟机ubuntu上安装git,想从github上拉取项目到ubuntu上的过程。

1、在ubuntu上安装git

        更新apt指令

sudo apt update

        安装git

sudo apt install git

        查看安装git版本

git --version

2、ssh认证

        首先已经安装了ssh指令

        先执行

ssh -T git@github.com
执行之后提示:Permission denied (publickey).

        接下来通过Ubuntu下的ssh-keygen命令创建公钥/私钥对:(使用你注册github时的邮箱)

ssh-keygen -C "1450053947@qq.com" -f ~/.ssh/github

        会得到下面提示

root@ljy-virtual-machine:~# ssh-keygen -C "1450053947@qq.com" -f ~/.ssh/github
Generating public/private rsa key pair.
/root/.ssh/github already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/github
Your public key has been saved in /root/.ssh/github.pub
The key fingerprint is:
SHA256:i8oSSUf/SVLNw2zPPx2FO55vq2S1b2787gtXOZ/hR4s 1450053947@qq.com

        去/root/.ssh下查看

root@ljy-virtual-machine:~# ls ~/.ssh
github  github.pub  known_hosts

        发现有刚才生成的私钥github和公钥github.pub

        查看公钥,并将公钥复制到github的框里(下图红框里的内容复制到github框里)

cat /root/.ssh/github.pub

 

 

git@github.com: Permission denied (publickey).

         此时在运行指令

ssh -T git@github.com

        如果提示让输入yes就输入yes,然后再次执行上面的指令。

        如果此时仍然提示

git@github.com: Permission denied (publickey).

        那么可使用下面指令进行调试

ssh -T -v git@github.com

        得到信息为:

root@ljy-virtual-machine:~# ssh -T -v git@github.com
OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to github.com [20.205.243.166] port 22.
debug1: Connection established.
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa_sk type -1
debug1: identity file /root/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: identity file /root/.ssh/id_ed25519_sk type -1
debug1: identity file /root/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /root/.ssh/id_xmss type -1
debug1: identity file /root/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
debug1: Remote protocol version 2.0, remote software version babeld-2aa8e17d
debug1: no match: babeld-2aa8e17d
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM
debug1: Host 'github.com' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /root/.ssh/id_rsa 
debug1: Will attempt key: /root/.ssh/id_dsa 
debug1: Will attempt key: /root/.ssh/id_ecdsa 
debug1: Will attempt key: /root/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /root/.ssh/id_ed25519 
debug1: Will attempt key: /root/.ssh/id_ed25519_sk 
debug1: Will attempt key: /root/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ecdsa_sk
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Trying private key: /root/.ssh/id_ed25519_sk
debug1: Trying private key: /root/.ssh/id_xmss
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).

        看以上信息发现是

debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ecdsa_sk
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Trying private key: /root/.ssh/id_ed25519_sk
debug1: Trying private key: /root/.ssh/id_xmss
debug1: No more authentication methods to try.

        这几个的问题,意思是一直在尝试获取/root/.ssh/id_rsa      /root/.ssh/id_dsa

        使用指令,发现没有id_rsa 和id_dsa

root@ljy-virtual-machine:~# ls ~/.ssh
github  github.pub  known_hosts

        因此来到/root/.ssh下

cd ~/.ssh

        使用下面指令,copy它们两个

root@ljy-virtual-machine:~/.ssh# cp github id_rsa && cp github.pub id_rsa.pub

        再次执行命令

ssh -T git@github.com

得到提示信息:

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

3、总结

        以上就是整个配置git的内容,可能写的不是很仔细,认真看应该没问题,看好你!!!嘻嘻

借鉴博客:

Ubuntu下使用git提交代码至GitHub - 走看看

关于ssh连接主机,git连接github失败的问题:ssh -T git@github.com&&Permission denied (publickey)_SunnyPotter的博客-CSDN博客

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐