0. 本次的目的为,创建一个work用户,设置密码并允许其使用SSH密码登录

1. 首先使用ec2-user这个用户登录到服务器

$ ssh ec2-user@123.4.5.6

2. 切换到root用户

$ sudo su

3. 创建新用户 work

# adduser work

4. 修改新用户 work 密码

# passwd work

5. 添加新的组 SSHD_USER

# groupadd SSHD_USER

6. 将新用户 work 添加到 SSHD_USER 组

# usermod -G SSHD_USER work

7. 修改 SSHD 配置文件

# vim /etc/ssh/sshd_config

在 sshd_config 文件末尾增加以下配置

# 允许登录的组: SSHD_USER ec2-user
AllowGroups SSHD_USER root ec2-user

# 仅允许 SSHD_USER 组使用密码登录
Match Group SSHD_USER
    PasswordAuthentication yes

8. 重启 SSHD 服务

# systemctl restart sshd

9. 检查 SSHD 服务状态

[root@server ec2-user]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since 一 2022-02-28 11:39:11 UTC; 15h ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 3806 (sshd)
   CGroup: /system.slice/sshd.service
           └─3806 /usr/sbin/sshd -D

3月 01 01:47:39 ip-172-26-2-26.ap-southeast-1.compute.internal sshd[25843]: input_userauth_request: invalid user ubuntu [preauth]
3月 01 01:47:39 ip-172-26-2-26.ap-southeast-1.compute.internal sshd[25839]: input_userauth_request: invalid user opc [preauth]
3月 01 01:47:39 ip-172-26-2-26.ap-southeast-1.compute.internal sshd[25846]: input_userauth_request: invalid user test [preauth]
3月 01 01:47:39 ip-172-26-2-26.ap-southeast-1.compute.internal sshd[25838]: input_userauth_request: invalid user ubuntu [preauth]
3月 01 01:47:39 ip-172-26-2-26.ap-southeast-1.compute.internal sshd[25837]: input_userauth_request: invalid user oracle [preauth]
3月 01 01:47:39 ip-172-26-2-26.ap-southeast-1.compute.internal sshd[25840]: input_userauth_request: invalid user vagrant [preauth]

此处要注意! 务必确保服务的状态为 running 

Active: active (running)

10. 测试新用户是否可以登录

$ ssh work@123.4.5.6

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐