以下是在CentOS镜像中配置SSH远程登录的步骤:
安装SSH服务
sudo yum install -y openssh-server
启动并设置开机自启
sudo systemctl start sshd
sudo systemctl enable sshd
配置SSH参数(可选)
编辑配置文件 /etc/ssh/sshd_config,可修改以下选项:
Port 2222(默认22,可自定义)PermitRootLogin no(推荐)PasswordAuthentication yes/no(推荐设为no,改用密钥认证)AllowUsers username(指定可登录用户)sudo systemctl restart sshd
配置防火墙
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
sudo service iptables save
测试连接
从本地机器使用SSH客户端连接:
ssh username@服务器IP -p 端口号(默认22)
安全建议:
ssh-keygen生成公钥,ssh-copy-id复制到服务器)替代密码认证。