当前位置: 首页 > article >正文

[运维]6.github 本地powershell登录及设置ssh连接

当我在本地的git hub 进行修改后,需要推送到远程github仓库。

当我运行了git add .   git commit -m "ingress-controller image" 以后,运行git push origin main,发现由于网络原因无法连接到远程github仓库。

此时开始设置ssh连接。首先在本地生成密钥,使用ssh-keygen命令:

-t 是指定密钥类型的参数。在这里,-t rsa 表示生成 RSA 类型的密钥。- b表示输出的密钥长度为4096位,-C 是为密钥添加注释的参数。"example@163.com" 是我为这个密钥添加的注释。

PS E:\git_image_repository\agent_image> ssh-keygen -t rsa -b 4096 -C "example@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\hades/.ssh/id_rsa):
Created directory 'C:\\Users\\hades/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\hades/.ssh/id_rsa
Your public key has been saved in C:\Users\hades/.ssh/id_rsa.pub
The key fingerprint is:
fsfhlsfhslfsbxvbdvvasvavsalufw
The key's randomart image is:
xxxxxx

执行ssh-keygen命令后,系统会询问你将密钥存储在哪里,否则会存储在默认的位置,这里我点击了回车,直接存储在默认位置。随后问了一个passphrase,两次回车跳过。则rsa密钥被存储好了。

通过cat 命令来查看自己的rsa 密钥。

PS E:\git_image_repository\agent_image> cat ~/.ssh/id_rsa.pub
ssh-rsa XXXXXXX

登录github网页版,并点击自己的头像,找到settings选项。 

 点击ssh and GPG keys

 点击新建ssh key,并将自己电脑上的rsa 密钥粘贴进去。第一步点击new SSH key进行创建,2通过创建成功后的ssh key。

 此时就可以在git powershell进行操作了。可以执行ssh -T git@github.com进行验证连接:

PS E:\git_image_repository\agent_image> ssh -T git@github.com
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
Hi 5703840! You've successfully authenticated, but GitHub does not provide shell access.

出现这个提示表示连接成功,其中这条信息表示 GitHub 的主机密钥已经成功添加到你的 ~/.ssh/known_hosts 文件中。之后再连接到 github.com 时,SSH 会自动验证主机密钥,无需再次手动确认。

Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.

切换url和ssh连接方式 

以下语句分别是设置用ssh的方式连接(git@github.....)和url的连接方式(https://github.com...)

git remote set-url origin git@github.com:fejlfj/agent_image.git
git remote set-url origin https://github.com/fejlfj/agent_image.git


http://www.kler.cn/news/336691.html

相关文章:

  • Golang 进阶4—— 网络编程
  • ASK, PSK, FSK, DPSK
  • 代码随想录--字符串--重复的子字符串
  • 今日指数day8实战补充(上)
  • Git 下载及安装超详教程(2024)
  • 算法专题四: 前缀和
  • 关于PyCharm【常见问题、解决方案等】
  • 磁盘存储、B树、B+树
  • 路由器的工作机制
  • helm 测试升级与回滚
  • 重学SpringBoot3-集成Redis(六)之消息队列
  • 解决 OpenCloudOS 中 yum 安装 yum-utils 命令报错的问题
  • RK3568笔记六十四:SG90驱动测试
  • Linux复习--Linux服务管理类(SSH服务、DHCP+FTP、DNS服务、Apache服务、Nginx服务、HTTP状态码)
  • D - Connect the Dots Codeforces Round 976 (Div. 2)
  • 基于SSM的高校勤工助学管理系统的设计与实现(源码+定制+参考文档)
  • 电影选票选座系统|影院购票|电影院订票选座小程序|基于微信小程序的电影院购票系统设计与实现(源码+数据库+文档)
  • 并查集的模拟实现
  • xtu oj 神经网络
  • linux下cmake编译64位,32位,ARM,ARM64程序