Linux Minimal 远程管理实操指南
一、首选方式 SSH 远程管理
sudo apt update && sudo apt install -y openssh-server,随后 sudo systemctl enable --now ssh(或 sudo systemctl start ssh)。检查状态:sudo systemctl status ssh。ssh username@server_ip。sudo yum install -y openssh-server,随后 sudo systemctl enable --now sshd。检查状态:sudo systemctl status sshd。ssh username@server_ip。sudo ufw allow 22/tcp;如改用其他端口(如 2222),放行对应端口:sudo ufw allow 2222/tcp。sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload;如更改端口,放行端口号:sudo firewall-cmd --permanent --add-port=2222/tcp && sudo firewall-cmd --reload。ip addr show 或 hostname -I 查看可用地址。二、图形化远程桌面方案
sudo apt-get install -y x11vnc,设置密码 x11vnc -storepasswd;创建服务文件 /etc/systemd/system/x11vnc.service(示例:/usr/bin/x11vnc -display :0 -auth /home/your_username/.Xauthority -forever -loop -noxdamage -repeat -rfbauth /home/your_username/.vnc/passwd -rfbport 5900 -shared),随后 sudo systemctl enable --now x11vnc。客户端用 5900 端口连接。sudo apt-get install -y tigervnc-standalone-server,设置密码 vncpasswd,启动会话 vncserver :1,默认端口 5901;如需放行:sudo ufw allow 5901/tcp。sudo apt-get install -y xrdp,启动 sudo systemctl enable --now xrdp,Windows 使用远程桌面连接 3389 端口。sudo yum install -y tigervnc-server tigervnc-common,设置密码 vncpasswd,启动会话 vncserver :1 -geometry 1920x1080;创建 /etc/systemd/system/vncserver@.service(设置 User、PIDFile、ExecStart 等),随后 sudo systemctl daemon-reload && sudo systemctl enable --now vncserver@1.service。客户端连接 5901 端口。三、安全加固要点
/etc/ssh/sshd_config,设置 PermitRootLogin no。ssh-keygen,将公钥追加到服务器 ~/.ssh/authorized_keys,在 sshd_config 中设置 PasswordAuthentication no 与 PubkeyAuthentication yes,重启 sshd。sshd_config 中设置 Port 2222,同时防火墙放行新端口,客户端使用 ssh -p 2222 user@ip。sshd_config 中使用 AllowUsers youruser,仅允许指定账户登录。四、常见问题排查
sudo systemctl status ssh 或 sudo systemctl status sshd,必要时 sudo systemctl restart ssh/sshd。-p 端口。