首页 > 其他分享 >第一次通过 SSH key 免密连接 GitHub 的完整过程

第一次通过 SSH key 免密连接 GitHub 的完整过程

时间:2024-01-27 20:58:21浏览次数:32  
标签:GitHub 免密 SSH key ed25519 com ssh

原文:https://ichochy.com/posts/blog/20221107.html


通过密码连接GitHub总是要输入密码,麻烦,现在使用 SSH key 可以轻松实现免密验证.

创建 SSH key

使用 ssh-keygen 命令

  • 打开终端输入命令 ssh-keygen 创建 key
ssh-keygen -t ed25519 -C "[email protected]" 

注意:将[email protected]换成自己的邮箱。

  • 命令构建ed25519 key,并自动保存到.ssh目录
Generating public/private ed25519 key pair.
Enter file in which to save the key (/Users/mleo/.ssh/id_ed25519): 
Created directory '/Users/mleo/.ssh'.
  • 提示输入key的密码
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

注意:可以输入空和密码

  • 提示key创建成功,并保存在.ssh目录
Your identification has been saved in /Users/mleo/.ssh/id_ed25519
Your public key has been saved in /Users/mleo/.ssh/id_ed25519.pub

配置 SSH key

  • 创建配置文件
touch ~/.ssh/config
  • 配置文件写入GitHub主机信息
Host github.com                           # 别名
	Hostname 	github.com                # GitHub 主机地址
	Port 		22                        # GitHub 主机端口
	User 		git                       # GitHub 主机用户
	Identityfile ~/.ssh/id_ed25519        # ssh-key
  • GitHub帐号中添加公钥key
iChochy(用户) => Settings => SSH and GPG keys => new SSH key

key

测试 SSH key

  • 测试 GitHub SSH 连接
ssh -T [email protected]
  • 确认是否连接
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确认连接
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 iChochy! You've successfully authenticated, but GitHub does not provide shell access.

使用 SSH key

  • 通过 SSH 地址克隆远程仓库
git clone [email protected]:iChochy/iChochy.git 	# 克隆远程仓库 
  • 通过 SSH 免密提交代码
Enumerating objects: 405, done.
Counting objects: 100% (405/405), done.
Delta compression using up to 8 threads
Compressing objects: 100% (205/205), done.
Writing objects: 100% (206/206), 27.81 KiB | 6.95 MiB/s, done.
Total 206 (delta 199), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (199/199), completed with 194 local objects.
To github.com:iChochy/iChochy.git
   1d44cdb..bde62c3  master -> master

相关文章

标签:GitHub,免密,SSH,key,ed25519,com,ssh
From: https://www.cnblogs.com/ichochy/p/17991917

相关文章

  • 无法访问Github仓库的极简治标法
    Github访问受限,是国内众多IP所经常面临的问题。这里我经过大量的踩坑之后,还是认为使用Gitee将Github的仓库直接同步过来,作为一个私有的镜像,是最便利高效的方法。当然,这个只能满足日常使用第三方库的需求,治标但不治本,对于那些仅仅只是想使用某些Github仓库代码的童鞋来说,也......
  • 【小记】Docker容器间SSH公钥自动交换实现免密登录的一次尝试
    咋想到这茬了最近开始忙毕设的事儿了,想部署个伪分布式的Spark+Hadoop集群来进行测试。思来考去,最终咱把目光放在了Docker上。盘了两天,发现这玩意意外的有趣,镜像构建好后开箱即用,省去了些配置环境的成本。不过呢,在配置Hadoop的时候我发现了一个问题——Hadoop分布式搭建要求各......
  • Failed to connect to github.com port 443 after 21051 ms: Couldn't connect to ser
    使用git克隆远程仓库的代码,总是显示连接不上服务器,https和ssh都试了还是连不上。打开cmd去pinggithub.com也是显示连接超时,但是浏览器里面还是可以正常访问github。网上搜了一下,使用"ipconfig/flushdns"在cmd里面刷新一下本地的dns缓存,还是不行。最后找到一个方法,修改本地hosts文......
  • github在线python数据分析JupyterLite配置
    1、登录个人github账号访问jupyterlite在github的网站,https://github.com/jupyterlite/demo,并将该仓库克隆到个人账户下;Usethistemplate --> ... 2、转到个人github界面下,点击图中设置部分 3、然后选择Pages选项,将默认行为改为GithubActions 4、接下来还需要......
  • github action 自动化部署asp.net core应用到服务器
    在自己的仓库里工作流编辑workflow贴上自己的工作流name:ASP.NETCoreDeploymenton:push:branches:-master#你可以根据需要更改分支名称(在向master分支推送的时候触发这个workflow)jobs:deploy:runs-on:ubuntu-latest#使用Ubuntu环......
  • VsCode SSH连接Ubuntu
    1.下载官方插件Remote-SSH2.虚拟机查看ip地址ipaddr3.配置config文件连接失败过程试图写入的管道不存在。解决重启ubuntureboot修改设置,将网络连接方式NAT➡桥接网卡如果Ubuntuip地址是10.0.*.*,设法将ip地址变为192.168.*.*连接成功免密连......
  • 《HelloGitHub》第 94 期
    兴趣是最好的老师,HelloGitHub让你对编程感兴趣!简介HelloGitHub分享GitHub上有趣、入门级的开源项目。https://github.com/521xueweihan/HelloGitHub这里有实战项目、入门教程、黑科技、开源书籍、大厂开源项目等,涵盖多种编程语言Python、Java、Go、C/C++、Swift.........
  • 解决 fatal: unable to access 'https://github.com/alibaba/nacos.git/': Failed to
    直接打开这个网站:https://sites.ipaddress.com/github.com/。找到网站中的IP地址复制出里面的IPAddress并粘贴到hosts里面。以下是macos上使用命令行打开方式,也可以直接在硬盘上找到这个文件打开sudovim/private/etc/hosts在最后一行添加如下代码140.82.113.4githu......
  • centos服务器修改ssh端口号
    1、修改ssh配置文件,找到Port=22位置,可以新增Port=20022,或者修改22为20022vi/etc/ssh/sshd_config  2、重启ssh服务systemctl restartsshd 3、查看ssh服务状态systemctl  status  sshd注:这里可以查看到ssh启动时监听端口的日志,如果监听失败会显示failed,失败......
  • git创建SSH keys
    git出现Pleasemakesureyouhavethecorrectaccessrightsandtherepositoryexists,需要创建SSHkeys。步骤:1、打开Git.bash进行命令行界面输入代码如下: gitconfig--globaluser.name"YourName"#配置user.namegitconfig--globaluser.email"your_email@exa......