安装SSH服务器
执行命令:sudo yum install openssh-server。
启动并启用SSH服务
sudo systemctl start sshd
sudo systemctl enable sshd
配置防火墙(CentOS 7及以上)
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
获取服务器IP地址
ip addr show
# 或
hostname -I
客户端连接服务器
使用命令:ssh username@server_ip(首次连接需确认服务器公钥,输入“yes”)。
安全建议:
/etc/ssh/sshd_config,设置PermitRootLogin no。~/.ssh/authorized_keys文件。