ubuntu 搭建 sshd 服务 git http 服务

创建日期: 2024-07-19 12:53 | 作者: 风波 | 浏览次数: 15 | 分类: OS

使用 ubuntu:24.04 镜像

搭建 shd 服务

  1. 替换 apt 源
find /etc/apt/ -type f| grep -Ei 'sources' | xargs -I {} sed -i 's#http://security.ubuntu.com#http://mirrors.aliyun.com#g' {}
find /etc/apt/ -type f| grep -Ei 'sources' | xargs -I {} sed -i 's#http://archive.ubuntu.com#http://mirrors.aliyun.com#g' {}
find /etc/apt/ -type f| grep -Ei 'sources' | xargs -I {} sed -i 's#^deb#deb [trusted=yes] #g' {}
find /etc/apt/ -type f| grep -Ei 'sources' | xargs -I {} sed -i 's#^deb#deb [trusted=yes] #g' {}
  1. 设置环境变量,避免 build docker 镜像时进行交互
ENV DEBIAN_FRONTEND noninteractive
  1. 安装 sshd 服务
apt update
apt install -y openssh-server openssh-client git nginx
  1. 设置权限目录
mkdir /run/sshd
chmod 755 /run/sshd
  1. 启动 sshd 服务
/usr/sbin/sshd -D

如果需要设置 key,可以使用下面的命令设置

ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

至此 sshd 服务搭建完成

搭建 git http 服务

  1. 修改 nginx 配置 删除 /etc/nginx/nginx.conf 中的 include /etc/nginx/sites-enabled/*;/etc/nginx/conf.d/git-server.conf 增加 user git; 增加文件 /etc/nginx/conf.d/git-server.conf
server {
    listen 80;
    server_name _;

    #access_log /var/log/nginx/git.example.com.log;
    #error_log /var/log/nginx/git.example.com_error.log info;

    # Redirect all non-HTTPS traffic to the HTTPS variant
    #return 301 https://$host$request_uri;
    location ~ \.git {
        # Set chunks to unlimited, as the body's can be huge
        client_max_body_size            0;

        include     fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME     /usr/lib/git-core/git-http-backend;
        fastcgi_param   GIT_HTTP_EXPORT_ALL "";
        fastcgi_param   GIT_PROJECT_ROOT    /git;
        fastcgi_param   PATH_INFO       $uri;

        # Forward REMOTE_USER as we want to know when we are authenticated
        fastcgi_param   REMOTE_USER     $remote_user;
        fastcgi_pass    unix:/var/run/fcgiwrap.socket;
    }
}
15 浏览
12 爬虫
0 评论