在CentOS系统中,实现多用户登录SSH主要涉及到以下几个方面:
确保SSH服务器已经安装并运行。CentOS默认已经安装了OpenSSH服务器。
sudo systemctl status sshd
如果未运行,启动SSH服务:
sudo systemctl start sshd
编辑SSH配置文件 /etc/ssh/sshd_config,确保以下配置项正确:
# 允许root用户登录(可选)
PermitRootLogin yes
# 允许使用公钥认证(推荐)
PubkeyAuthentication yes
# 允许使用密码认证(如果需要)
PasswordAuthentication yes
# 允许使用键盘交互式认证(如果需要)
ChallengeResponseAuthentication yes
# 允许使用GSSAPI认证(如果需要)
GSSAPIAuthentication yes
# 允许使用Kerberos认证(如果需要)
KerberosAuthentication yes
# 允许使用LDAP认证(如果需要)
UsePAM yes
创建多个用户账户,每个用户都有自己的主目录和权限。
sudo adduser user1
sudo adduser user2
确保每个用户的主目录权限正确,只有该用户自己可以访问。
sudo chown user1:user1 /home/user1
sudo chmod 700 /home/user1
sudo chown user2:user2 /home/user2
sudo chmod 700 /home/user2
为了提高安全性,建议使用SSH密钥认证。
在客户端生成SSH密钥对:
ssh-keygen -t rsa -b 4096 -C "user1@example.com"
将生成的公钥复制到服务器的 ~/.ssh/authorized_keys 文件中。
ssh-copy-id user1@server_ip
ssh-copy-id user2@server_ip
确保防火墙允许SSH连接。
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
使用不同的用户账户尝试SSH登录服务器,确保配置正确。
ssh user1@server_ip
ssh user2@server_ip
定期检查SSH日志文件 /var/log/secure,监控登录活动和潜在的安全问题。
sudo tail -f /var/log/secure
通过以上步骤,你可以在CentOS系统上实现多用户SSH登录,并确保系统的安全性和稳定性。