CentOS 8 默认已经安装了OpenSSH服务。如果没有安装,可以使用以下命令安装:
sudo dnf install -y openssh-server安装完成后,需要启动SSH服务并设置为开机自启:
sudo systemctl start sshd
sudo systemctl enable sshd确保防火墙允许SSH连接。您可以使用firewalld来管理防火墙规则:
sudo firewall-cmd --add-service=ssh --permanent
sudo firewall-cmd --reloadSSH服务的配置文件位于/etc/ssh/sshd_config。您可以编辑该文件来配置SSH服务。例如,修改默认的端口号:
sudo nano /etc/ssh/sshd_config找到以下行并修改:
# Port 22
Port 2222保存文件并退出编辑器。然后重启SSH服务以应用更改:
sudo systemctl restart sshd为了更安全地进行SSH连接,可以生成公钥和私钥:
ssh-keygen -t rsa -b 4096将生成的公钥传输到远程主机:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote_hostUbuntu 20.04 默认已经安装了OpenSSH服务。如果没有安装,可以使用以下命令安装:
sudo apt update
sudo apt install -y openssh-server安装完成后,需要启动SSH服务并设置为开机自启:
sudo systemctl start ssh
sudo systemctl enable ssh确保防火墙允许SSH连接。您可以使用ufw来管理防火墙规则:
sudo ufw allow ssh
sudo ufw enableSSH服务的配置文件位于/etc/ssh/sshd_config。您可以编辑该文件来配置SSH服务。例如,修改默认的端口号:
sudo nano /etc/ssh/sshd_config找到以下行并修改:
# Port 22
Port 2222保存文件并退出编辑器。然后重启SSH服务以应用更改:
sudo systemctl restart ssh为了更安全地进行SSH连接,可以生成公钥和私钥:
ssh-keygen -t rsa -b 4096将生成的公钥传输到远程主机:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote_host项目 | CentOS 8 | Ubuntu 20.04 |
|---|---|---|
安装SSH服务 | sudo dnf install -y openssh-server | sudo apt update && sudo apt install -y openssh-server |
启动SSH服务 | sudo systemctl start sshd | sudo systemctl start ssh |
开机自启SSH | sudo systemctl enable sshd | sudo systemctl enable ssh |
配置防火墙 | sudo firewall-cmd --add-service=ssh --permanent sudo firewall-cmd --reload | sudo ufw allow ssh sudo ufw enable |
配置文件路径 | /etc/ssh/sshd_config | /etc/ssh/sshd_config |
修改端口号 | 编辑/etc/ssh/sshd_config,修改Port行 | 编辑/etc/ssh/sshd_config,修改Port行 |
重启SSH服务 | sudo systemctl restart sshd | sudo systemctl restart ssh |
生成密钥对 | ssh-keygen -t rsa -b 4096 | ssh-keygen -t rsa -b 4096 |
传输公钥 | ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote_host | ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote_host |
无论是CentOS 8还是Ubuntu 20.04,创建和配置SSH服务的步骤大体相同,主要区别在于包管理工具和防火墙管理工具的命令不同。希望这些步骤和命令能帮助您顺利配置SSH服务。如果有任何其他问题或需要进一步的帮助,请随时提问!