使用本教程首次配置您的 CentOS 8 Linux 计算机。例如,您使用 CentOS 8 启动了新的 VPS 或专用主机,请按照以下步骤完成 CentOS 8 的初始服务器设置。
第 1 步 – 登录 CentOS 8
登录到您的 CentOS 8 Linux 计算机。桌面用户可以使用 GUI 界面登录。远程用户使用 SSH 访问连接到服务器。
ssh root@remote_server_ip
第 2 步 – 更新当前包
登录后,首先更新系统上的所有当前软件包。
dnf clean all
dnf update
第 3 步 – 安装所需的软件包
dnf install vim wget
第 4 步 – 创建用户帐户
一些云托管提供商(例如 DigitalOcean)仅提供 root 访问权限。这是为系统管理员工作创建单独帐户的最佳实践。
使用以下命令创建用户:
adduser rahul
然后为新创建的帐户设置一个强密码。
passwd rahul
您将需要 Sudo 权限才能执行系统管理任务。 CentOS Linux 系统有一个名为“wheel”的默认组,具有 Sudo 权限。将新创建的用户添加到wheel组。
usermod -aG wheel rahul
第 5 步 – 设置基本防火墙
如果您的 CentOS 8 默认安装没有安装防火墙,请按照以下步骤在 CentOS 8 上设置防火墙。
dnf install firewalld
安装后,启动防火墙服务并使其在系统启动时自动启动。
systemctl start firewalld
systemctl enable firewalld
默认情况下,防火墙允许远程用户进行 SSH 访问。您可能还需要允许其他服务通过防火墙提供给远程用户。
您可以直接提供“http”或“https”等服务名称来允许。 Firewalld 使用 /etc/services 文件来确定服务对应的端口。
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
如果/etc/services中没有定义服务名,则直接添加允许通过端口号访问。例如,允许防火墙使用 TCP 端口 8080 或 10000(默认 Webmin)。
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --permanent --add-port=10000/tcp
对防火墙进行任何更改后,请确保使用以下命令重新加载更改。
firewall-cmd --reload
要查看所有允许的端口和服务,请使用以下命令。
firewall-cmd --permanent --list-all
Output:
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: cockpit dhcpv6-client http https ssh
ports: 8080/tcp 10000/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
结论
您的 CentOS 8 系统已可供使用。谢谢。