连接到您的服务器并进行初始配置
服务器开通后,您可以在我的服务器页面查看连接信息:
Windows 10/11 自带 OpenSSH 客户端,可以直接使用 PowerShell 或命令提示符:
ssh root@your-server-ip
或者使用 PuTTY:
打开终端,使用 ssh 命令连接:
ssh root@your-server-ip
第一次连接时会提示确认主机指纹,输入 yes 继续:
The authenticity of host 'xxx.xxx.xxx.xxx' can't be established.
Are you sure you want to continue connecting (yes/no)? yes
首次登录后,建议立即修改 root 密码:
passwd
按提示输入新密码两次即可。
为了安全起见,建议创建一个普通用户用于日常操作:
# 创建新用户
adduser username
# 将用户添加到 sudo 组
usermod -aG sudo username
之后可以使用新用户登录,需要 root 权限时加上 sudo:
ssh username@your-server-ip
sudo apt update
使用密钥登录比密码更安全,建议配置:
ssh-keygen -t ed25519 -C "[email protected]"
ssh-copy-id root@your-server-ip
或者手动复制:
# 在本地查看公钥
cat ~/.ssh/id_ed25519.pub
# 复制内容到服务器的 ~/.ssh/authorized_keys 文件
配置密钥登录成功后,可以禁用密码登录提高安全性:
# 编辑 SSH 配置文件
nano /etc/ssh/sshd_config
# 修改以下配置
PasswordAuthentication no
PermitRootLogin prohibit-password
# 重启 SSH 服务
systemctl restart sshd
# Ubuntu/Debian
apt update && apt upgrade -y
# CentOS/Rocky/Alma
dnf update -y
# Ubuntu/Debian
apt install -y vim curl wget htop net-tools ufw
# CentOS/Rocky/Alma
dnf install -y vim curl wget htop net-tools firewalld
# Ubuntu/Debian (UFW)
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
# 查看状态
ufw status
配置防火墙时,请确保 SSH 端口(默认22)是开放的,否则您将无法连接到服务器。如果修改了 SSH 端口,记得允许新端口。
完成基础配置后,您可以:
更多详细教程请参考控制面板使用指南。