github_ssh_免密登录


Github ssh key生成,免密登录服务器方法

生成sshkey

1、查看是否存在ssh key,如果有会列出key的列表

1
2
$ ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

2.生成密钥 参数说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ ssh-keygen -t rsa -C "snailfrying@gmail.com"
Too many arguments.
usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa]
[-N new_passphrase] [-C comment] [-f output_keyfile]
ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
ssh-keygen -i [-m key_format] [-f input_keyfile]
ssh-keygen -e [-m key_format] [-f input_keyfile]
ssh-keygen -y [-f input_keyfile]
ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]
ssh-keygen -B [-f input_keyfile]
ssh-keygen -D pkcs11
ssh-keygen -F hostname [-f known_hosts_file] [-l]
ssh-keygen -H [-f known_hosts_file]
ssh-keygen -R hostname [-f known_hosts_file]
ssh-keygen -r hostname [-f input_keyfile] [-g]
ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]
ssh-keygen -T output_file -f input_file [-v] [-a rounds] [-J num_lines]
[-j start_line] [-K checkpt] [-W generator]
ssh-keygen -s ca_key -I certificate_identity [-h] [-U]
[-D pkcs11_provider] [-n principals] [-O option]
[-V validity_interval] [-z serial_number] file ...
ssh-keygen -L [-f input_keyfile]
ssh-keygen -A
ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]
file ...
ssh-keygen -Q -f krl_file file ...

3.运行日志

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#存储密钥路径 /users/admin/   woniu@DESKTOP-04BM85Q MINGW64 ~/.ssh (master)
$ cd ~/.ssh
#查看是否已有历史密钥文件
$ ls
id_rsa id_rsa.pub known_hosts
#如果有则删除
$ rm *
#回到当前路径
$ cd ~
#生成密钥
$ ssh-keygen -t rsa -C "snailflying@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/woniu/.ssh/id_rsa):#直接回车
Enter passphrase (empty for no passphrase):#输入github密码
Enter same passphrase again:#再一次输入github密码
Your identification has been saved in /c/Users/woniu/.ssh/id_rsa.
Your public key has been saved in /c/Users/woniu/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:EIJXUUfM0KGak/6U69zVf+ux2ZKcgD9ZVjt2o/osQRE snailfrying@gmail.com
The key's randomart image is:
+---[RSA 2048]----+
| ...+oo*+E. |
| . .. . o+. |
| . . . . |
| = . .|
| = S .. ..|
| . . .....o=.|
| . o .o*+++|
| + o o=.=.*|
| .= ..++.*=|
+----[SHA256]-----+
#进入生成密钥存储文件
$ cd .ssh
woniu@DESKTOP-04BM85Q MINGW64 ~/.ssh (master)
#查看
$ ls
id_rsa id_rsa.pub
#查看公共密钥,粘贴进github主页存储密钥路径
#即github主页(头像)--> settings --> SSH and GPG keys --> SSH keys
#删除已有key,重新导入 下列输出公钥
$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTt4T7Ht1+uYW9eZhecy/ztAQ0X3WujF1rwXeTlHRgMBk6iTPvOVO34WnmThOcvv3cLkUiYHNJB8SfihjikoILgJUWFwMEXLC/kOZMhy/UXh9QQZuGksS6ExXuw/WRVgzJ99jzAwyqXG+cMgoUt5CnuPUD15HLstHj8wzMajHJ8+eUny2BiQDzIqAg07Hj7xXtVwMOPXH+fVMhQ6yUEqEhDMEt0udjuz8zcBzY5vwlWHISexvuw2ktoC2TpY8KbB3YB1HazE53ixP7l0qBRkt+6Vpk2dKrjyUWOj5u+mBXowJjaEJGje6IeiCXwbOdyaflirdnzPy+8B9FwwJFVEs7 snailfrying@gmail.com

#配置账户
$ git config --global user.name "snailfrying"
#配置邮箱
$ git config --global user.email "snailfrying@gmail.com"
#验证是否成功
$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.255.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.255.112' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/woniu/.ssh/id_rsa':
Hi snailfrying! You've successfully authenticated, but GitHub does not provide shell access.
#推送到远程,实现同步
$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

git push --set-upstream origin master

#回到工程目录,进行提交
$ cd
$ cd D:
$ cd snail_blog
$ cd blog
$ hexo d g