在CentOS Minimal系统中使用SSH,你需要按照以下步骤操作:
首先,你需要安装OpenSSH服务器。打开终端并运行以下命令:
sudo yum install openssh-server
安装完成后,启动SSH服务并设置为开机自启:
sudo systemctl start sshd
sudo systemctl enable sshd
确保SSH服务正在运行:
sudo systemctl status sshd
如果服务未运行,可以使用以下命令启动它:
sudo systemctl start sshd
如果你的CentOS Minimal系统启用了防火墙(firewalld),你需要允许SSH连接:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
你需要知道服务器的IP地址才能从其他计算机连接到它。可以使用以下命令获取IP地址:
ip addr show eth0
将eth0
替换为你的网络接口名称(例如ens33
)。
使用SSH客户端从另一台计算机连接到你的CentOS Minimal服务器。打开终端并运行以下命令:
ssh username@server_ip_address
将username
替换为你的用户名,将server_ip_address
替换为你的服务器IP地址。
首次连接到服务器时,你可能会看到一个安全提示,询问是否继续连接。输入yes
并按回车键确认。
为了提高安全性,你可以设置SSH密钥认证而不是密码认证。以下是设置步骤:
ssh-keygen -t rsa -b 4096
按照提示操作,通常会生成~/.ssh/id_rsa
(私钥)和~/.ssh/id_rsa.pub
(公钥)文件。
使用以下命令将公钥复制到服务器的~/.ssh/authorized_keys
文件中:
ssh-copy-id username@server_ip_address
将username
替换为你的用户名,将server_ip_address
替换为你的服务器IP地址。
现在,你应该能够使用SSH密钥认证连接到服务器,而无需输入密码:
ssh username@server_ip_address
通过以上步骤,你应该能够在CentOS Minimal系统中成功使用SSH。