SSH服务详解(一)–Linux SSH 服务器与客户端的安装与启动
SSH服务详解(二)–使用私钥登录 SSH 服务器(免密登录)
SSH 服务详解 (三)-- 使用 SSH 代理
SSH 服务详解 (四)-- 本地调用远程主机的命令
SSH 服务详解 (五)-- 远程文件拷贝
SSH 服务详解 (六)-- Windows SSH 主机
SSH 服务详解 (七)-- SSH 连接 Github
本地(Windows)Linux 网上教程较多,这里以 Windows 为例
配置本地 git查看配置
git config --global --list
配置用户名
git config --gloabl user.name
配置邮箱
git config --global user.email生成秘钥
最好在 C:UsersAdmin.ssh 目录下生成秘钥(防止时间太久秘钥找不到)
在上述目录下打开 git bash
ssh-keygen.exe -t rsa -C "for ssh test"
- -t 表示类型
- -C 注释
提示输入秘钥名称
Enter file in which to save the key (/c/Users/Admin/.ssh/id_rsa): testssh
秘钥生成结果
Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in testssh. Your public key has been saved in testssh.pub. The key fingerprint is: SHA256:eEFl7kK7MYymu2xxAQ for ssh test The key's randomart image is: +---[RSA 2048]----+ | *=o | | ooo*. | |E .+o. | | . o *.++ | | B.S+.. | | o +.*.o. | | +. .. | | +o+oo | |oo | +----[SHA256]-----+
当前目录
$ ls config known_hosts testssh testssh.pub tyustli tyustli.pub
testssh 和 testssh.pub 为生成的秘钥对
Github 公钥添加Settings->SSH and GPG keys
点击 New SSH key
Title 输入名称,Key 输入公钥 testssh.pub
将生成的公钥 testssh.pub 内容复制到 Key 中即可
添加私钥 git bash 中添加私钥bash 中依次输入如下命令
ssh-agent ssh-add ~/.ssh/testssh
上述命令执行下来会报错
Could not open a connection to your authentication agent.
再执行一遍如下命令即可
ssh-agent bash # 表示在 bash 中开启 ssh 代理 ssh-add ~/.ssh/testssh # 添加 ssh 秘钥
注意:bash 关闭之后添加的 ssh 秘钥就失效了,下次再打开需要重新执行上述步骤
永久添加打开 git bash 时,需要将 ssh 密钥自动添加到每个会话中,那么如何一次添加永久使用呢?
打开 git 安装目录(D:SoftWare_ApplicationGitetcssh)下的 ssh_config 文件
在底部输入
IdentityFile path # path 表示 ssh 私钥的路径地址
例如
IdentityFile ~/.ssh/testsshssh 测试
$ ssh -T git@github.com
测试失败,秘钥未添加,参考 添加私钥 章节
git@github.com: Permission denied (publickey).
测试成功
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.



