在CentOS上设置GitLab时,确保系统安全是非常重要的。以下是一些关键的安全设置步骤:
/etc/passwd 文件来检测并管理这些账户。adm, lp, sync 等,以减少系统受攻击的风险。/etc/login.defs 文件来强制执行这些要求。chattr 命令给 /etc/passwd, /etc/shadow, /etc/group, 和 /etc/gshadow 文件加上不可更改属性。/etc/profile 文件中的 TMOUT 参数,设置root账户的自动注销时限。/etc/pam.d/su 文件,限制只有特定组的用户才能使用 su 命令切换为root。/etc/security/console.apps 下的相应程序的访问控制文件,防止普通用户执行关机、重启等敏感操作。firewalld 管理防火墙规则,仅允许必要的端口访问,如HTTP(80)和HTTPS(443)。.gitignore 文件忽略敏感信息文件,检查提交内容,防止敏感信息上传。安装依赖包:
sudo yum install -y curl policycoreutils-python openssh-server postfix wget vim
安装GitLab:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.1.0-ce.0.el7.x86_64.rpmsudo rpm -ivh gitlab-ce-14.1.0-ce.0.el7.x86_64.rpm
配置GitLab:
sudo vim /etc/gitlab/gitlab.rb
# 修改 external_url 为你的GitLab访问地址
external_url 'http://your_server_ip'
# 配置邮件服务器
gitlab_rails['smtp_enable'] true
gitlab_rails['smtp_address'] "smtp.qq.com"
gitlab_rails['smtp_port'] 465
gitlab_rails['smtp_user_name'] "your_email@example.com"
gitlab_rails['smtp_password'] "your_password"
gitlab_rails['smtp_domain'] "example.com"
gitlab_rails['smtp_authentication'] "login"
gitlab_rails['smtp_enable_starttls_auto'] true
gitlab_rails['smtp_tls'] true
gitlab_rails['gitlab_email_from'] 'your_email@example.com'
重置并启动GitLab服务:
gitlab-ctl reconfigure
gitlab-ctl restart
配置SSH认证:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
通过上述步骤,你可以显著提高GitLab在CentOS上的安全性,保护你的代码和数据不受未授权访问和潜在威胁的侵害。