二歪同学

  • 一、生成SSH Key
  • 初始化
  • 生成SSH Key
  • 二、获取KEY
  • 三、添加SSH密钥
  • 四、验证
  • 五、常见问题
  • 1.连接被远程主机关闭,连接由 198.18.1.87 端口 22 关闭
  • 解决方法:
  • 2.你已成功进行身份验证,但 GitHub 不提供 shell 访问权限。
  • 解决方法:
  • 博客首页
  • 三行代码
  • 运营笔记
  • 生活随笔
  • 杂项归档
  • 关于博主
  • 友情链接
  • 榜上有名
  • 文章归档
  • 扩展工具
    • 豆瓣影音
    • 博客图床
    • 网站监测
    • 在线网盘
  • 订阅博客
  • 联系博主
  • GitHub
  • Mail

GIT链接远程服务器常规操作及常见问题

  • 二歪同学
  • 2023-02-16
  • 0

一、生成SSH Key

初始化

git config --global user.name "名称或昵称" 
git config --global user.email "你的邮箱"

生成SSH Key

 ssh-keygen -t rsa -C "youremail@example.com"

二、获取KEY

后面的   your_email@youremail.com  改为你在 Github 上注册的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。

成功的话会在 ~/ 下生成 .ssh 文件夹,进去,打开 id_rsa.pub,复制里面的 key。

$ ssh-keygen -t rsa -C "youremail@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/tianqixin/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase):    # 直接回车
Enter same passphrase again:                   # 直接回车
Your identification has been saved in /Users/tianqixin/.ssh/id_rsa.
Your public key has been saved in /Users/tianqixin/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:MDKVidPTDXIQoJwoqUmI4LBAsg5XByBlrOEzkxrwARI 429240967@qq.com
The key's randomart image is:
+---[RSA 3072]----+
|E*+.+=**oo       |
|%Oo+oo=o. .      |
|%**.o.o.         |
|OO.  o o         |
|+o+     S        |
|.                |
|                 |
|                 |
|                 |
+----[SHA256]-----+

三、添加SSH密钥

登录(github.com),打开 Account => Settings。打开## SSH keys

四、验证

ssh -T git@github.com

成功提示:

The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes                   # 输入 yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Hi tianqixin! You've successfully authenticated, but GitHub does not provide shell access. # 成功信息

五、常见问题

1.连接被远程主机关闭,连接由 198.18.1.87 端口 22 关闭

kex_exchange_identification: Connection closed by remote host
Connection closed by 198.18.1.87 port 22

解决方法:

  • 关闭VPN;

2.你已成功进行身份验证,但 GitHub 不提供 shell 访问权限。

You’ve successfully authenticated, but GitHub does not provide shell access

解决方法:

  • 删除现有KEY并重新生成
  • 切换为SSH

首先使用 git remote -v 查看远程 URL 地址:

origin https://github.com/balala8/N0va_for_mac.git (fetch) 
origin https://github.com/balala8/N0va_for_mac.git (push)

如果显示为上方情况,则需要更改 URL 链接:

git remote set-url origin git@github.com:balala8/N0va_for_mac.git

之后再次通过 git remote -v 命令查看,显示为下方情况即可。

origin git@github.com:balala8/N0va_for_mac.git (fetch) 
origin git@github.com:balala8/N0va_for_mac.git (push)

之后如果仍提示 You've successfully authenticated, but GitHub does not provide shell access. ,无视即可,这句话仅代表github 不允许 shell 交互而已,实际上已经可以对远程仓库进行操作。

© 2023 二歪同学
Theme by Wing
鲁ICP备2021036422号
  • {{ item.name }}
  • {{ item.name }}