SSH(Secure Shell)是一种加密的网络协议,用于在不安全的网络上安全地运行网络服务。它主要用于远程登录会话和其他网络服务。SSH服务器允许用户通过SSH客户端安全地连接到Linux系统。
在大多数Linux发行版中,可以使用包管理器来安装OpenSSH服务器。
Debian/Ubuntu:
sudo apt update
sudo apt install openssh-server
CentOS/RHEL:
sudo yum install openssh-server
安装完成后,启动SSH服务并设置为开机自启。
Debian/Ubuntu:
sudo systemctl start sshd
sudo systemctl enable sshd
CentOS/RHEL:
sudo systemctl start sshd
sudo systemctl enable sshd
编辑SSH服务器的配置文件/etc/ssh/sshd_config
,根据需要进行配置。
示例配置:
# 允许root用户登录
PermitRootLogin no
# 设置默认端口(可选)
Port 2222
# 启用公钥认证
PubkeyAuthentication yes
# 禁用密码认证(推荐使用公钥认证)
PasswordAuthentication no
# 重启SSH服务以应用更改
sudo systemctl restart sshd
确保防火墙允许SSH连接。
Debian/Ubuntu (使用ufw):
sudo ufw allow 2222/tcp
sudo ufw reload
CentOS/RHEL (使用firewalld):
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
原因:
解决方法:
原因:
解决方法:
~/.ssh/authorized_keys
文件中。通过以上步骤,你应该能够在虚拟机上的Linux系统中成功安装和配置SSH服务器。
领取专属 10元无门槛券
手把手带您无忧上云