如题

配置全局用户信息

1
2
git config --global  user.name "你的用户名"
git config --global user.email "你的邮箱"

生成秘钥

执行以下命令生成秘钥:
ssh-keygen -t rsa -C “你的邮箱”
这一步,也可以参考:码云帮助文档 -> 生成并部署SSH key

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@centOS7BasicForTest config]# ssh-keygen -t rsa -C "***@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:d502E7pWZL9Mv5ZfwgIGY913sXlJWUdf7cw8N9wcEPQ ***@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| .+o+O|
| . . ooX|
| + . . *E*|
| . o * OX|
| S + o B.=|
| o o =ooo|
| + oo+|
| . . +o|
| ..o|
+----[SHA256]-----+

获取生成的 key

1
cat ~/.ssh/id_rsa.pub

参照码云的帮助页面,将 id_rsa.pub 的内容,粘贴至码云项目的公匙。

项目首页->管理->左侧->部署公钥管理->添加公钥,地址是https://gitee.com/uncleAndyChen/[projectName]/deploy_keys/new,其中 [projectName] 为你在 gitee 上的项目名。

以 ssh 的方式 clone 项目

1
git clone git@gitee.com:elsafly/doc.tech.git

之后,项目有更新,执行 git pull 即可。

Permission denied (publickey)

以下,用 unginx 的身份运行,没有权限,换成 root 用户即可。

原因是生成 ssh key 的是 root 用户,如果想以 unginx 身份执行 git clone ….,以 unginx 登录重新执行上面的步骤。

1
2
3
4
5
6
7
8
9
10
11
12
[unginx@centOS7BasicForTest apps]$ git clone git@gitee.com:elsafly/doc.tech.git
Cloning into 'doc.tech'...
The authenticity of host 'gitee.com (120.55.226.24)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
ECDSA key fingerprint is MD5:27:e5:d3:f7:2a:9e:eb:6c:93:cd:1f:c1:47:a3:54:b1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,120.55.226.24' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

应用

要在服务器上部署博客,只需写好脚本,定时执行,即可达到代码提交(push)之后,博客自动更新发布的目的。

1
2
3
4
5
[root@centOS7BasicForTest shell.script]# vi doc.tech.sh
cd /home/unginx/apps/doc.tech
git pull
#hexo clean #根据需要添加,建议不要这条命令
hexo g