连接步骤:
1.查看是否存在.ssh
cd ~/.ssh
dir
- 查看是否存在 id_rsa 和 id_rsa.pub
目录: C:\Users\Administrator\.ssh
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2018/10/24 14:08 1675 id_rsa
-a---- 2018/10/24 14:08 404 id_rsa.pub
-a---- 2018/10/24 14:19 408 known_hosts
- 如果存在直接跳到第三点
2. 生成ssh
ssh-keygen -t rsa -C "[email protected]"
双引号内,填写自己的邮箱账号
enter键,并输入密码(如果不想输密码,可以按enter键直接跳过)
ssh-keygen -t rsa -C "XXXXXX@gmail.com" #双引号中输入你的邮箱
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\Administrator/.ssh/id_rsa): #默认路径-->直接enter
Created directory 'C:\Users\Administrator/.ssh'. #此时会看到此路径下多了一个.ssh
Enter passphrase (empty for no passphrase): #直接enter
Enter same passphrase again: #直接enter
你将得到以下结果:
Your identification has been saved in C:\Users\Administrator/.ssh/id_rsa.
Your public key has been saved in C:\Users\Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:L+UPeE3k1WjplZIG3J2q43Dlvqx8UzBdvG4CbOCRc XXXXXX@gmail.com
The key's randomart image is:
+---[RSA 2048]----+
| |
| Eoo= |
| oo@*.|
| .ooX+.*|
| S .==++++|
| = o+..+=|
| o = o.o+o|
| o o *= |
| .*+.. |
+----[SHA256]-----+
3.将ssh添加到github
cat ~/.ssh/id_rsa.pub
复制公钥添加到ssh
具体步骤指路github官网 Adding a new SSH key to your GitHub account:https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
4.测试是否成功
指路github官网 Testing your SSH connection:https://help.github.com/articles/testing-your-ssh-connection/
ssh -T git@github.com
看最后一句,成啦~
ssh -T git@github.com
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.
我遇到的问题:
1.ssh未启动
ssh-agent
如果出现错误信息: unable to start ssh-agent service, error :1058
处理方法:
打开服务应用程序
- 按组合键:win+r
- 输入:services.msc
找到 OpenSSH Authentication Agent 启动并设置为自动
2.未以管理员身份运行