部署站点到服务器

部署站点到服务器

通过文件的方式

打包上传即可

通过 git 方式

在服务器上创建 git 仓库

安装 git

yum install git

创建 git 用户

adduser git
password git
// 修改权限
chmod 740 /etc/sudoers
// 编辑
vim /etc/sudoers
# 找到root ALL=(ALL) ALL,在它下方加入一行
git ALL=(ALL) ALL
chmod 400 /etc/sudoers

git 服务器打开 RSA 验证

vim /etc/ssh/sshd_config

sshd_config中设置以下几项:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile  .ssh/authorized_keys

配置 ssh

将 ssh 公钥复制粘贴到 git 用户目录中的.ssh 文件夹内的 authorized_keys 文件里

/home/git/.ssh/authorized_keys

ssh 命令测试

执行ssh命令测试是否可以免密登录ssh -v git@SERVER

ssh -v git@服务器的公网ip

创建git仓库

sudo mkdir -p /var/repo    #新建目录,这是git仓库的位置
sudo mkdir pp /var/www/hexo
cd /var/repo  #转到git仓库的文件夹
sudo git init --bare blog.git #创建一个名叫blog的仓库
sudo vim /var/repos/blog.git/hooks/post-update

post-update的内如如下

#!/bin/bash
git --work-tree=/www/wwwroot/website  --git-dir=/home/git/repos/blog.git checkout -f

给 post-update 授权

cd /home/git/repos/blog.git/hooks/
sudo chown -R git:git /home/git/repos/
sudo chown -R git:git /www/wwwroot/websit
sudo chmod +x post-update  #赋予其可执行权限

修改 git 用户默认 shell 权限

vim /etc/passwd
#修改最后一行git:x:1002:1002::/home/git:/usr/bin/bash
#将/bin/bash修改为/usr/bin/git-shell
部署站点到服务器
https://pic.imgdb.cn/item/64a3ac0f1ddac507ccac32ea.webp
作者
Firefly
发布于
2026-04-03
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
Firefly
Hello, I'm Firefly.
公告
欢迎来到我的博客!这是一则示例公告。
音乐
暂无封面

音乐

暂未播放

0:000:00
暂无歌词
暂无歌曲
分类
标签
站点统计
文章
21
分类
3
标签
13
总字数
57,102
运行时长
601
最后活动
143 天前

目录