●まずユーザを作成する
[root@rhel74 ~]# groupadd com
[root@rhel74 ~]# groupadd sftp
[root@rhel74 ~]# useradd -g com com
[root@rhel74 ~]# useradd -g sftp sftpuser1
[root@rhel74 ~]# useradd -g com -s /bin/false fal
[root@rhel74 ~]# useradd -g com -s /sbin/nologin nologin
[root@rhel74 ~]# useradd -g com locked
[root@rhel74 ~]# usermod -L locked
com 普通のユーザ
sftpuser1 グループがsftpのユーザ
fal /bin/falseのユーザ
nologin /sbin/nologinのユーザ
locked ロックされたユーザ
●sshログイン
[root@rhel74 ~]# ssh com@localhost →成功
[root@rhel74 ~]# ssh sftpuser1@localhost →成功
[root@rhel74 ~]# ssh fal@localhost →失敗
[root@rhel74 ~]# ssh nologin@localhost →失敗
[root@rhel74 ~]# ssh locked@localhost →失敗
●ftpログイン
[root@rhel74 ~]# ftp localhost
com 成功
sftpuser1 成功
fal 失敗
nologin 成功
locked 失敗
●sftpログイン
[root@rhel74 ~]# sftp com@localhost 成功
[root@rhel74 ~]# sftp sftpuser1@localhost 成功
[root@rhel74 ~]# sftp fal@localhost 失敗
[root@rhel74 ~]# sftp nologin@localhost 失敗
[root@rhel74 ~]# sftp locked@localhost 失敗
●sftpをinternal-sftpに変更
[root@rhel74 ~]# vi /etc/ssh/sshd_config
Subsystem sftp /usr/libexec/openssh/sftp-server
↓
Subsystem sftp internal-sftp
[root@rhel74 ~]# systemctl restart sshd
※sftpログインしたときにこうなる
[root@rhel75 ~]# ps -elf | grep sftp
4 S root 1707 1702 0 80 0 - 18040 poll_s 00:36 ? 00:00:00 /usr/libexec/openssh/sftp-server
↑変更前↓変更後
5 S root 3403 3399 0 80 0 - 36946 poll_s 00:37 ? 00:00:00 sshd: root@internal-sftp
●sftpログイン
[root@rhel74 ~]# sftp com@localhost 成功
[root@rhel74 ~]# sftp sftpuser1@localhost 成功
[root@rhel74 ~]# sftp fal@localhost 成功
[root@rhel74 ~]# sftp nologin@localhost 成功
[root@rhel74 ~]# sftp locked@localhost 失敗
●sftpグループのユーザがsshログインできないようにする
[root@rhel74 ~]# vi /etc/ssh/sshd_config
Match group sftp
ChrootDirectory /home/%u
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
[root@rhel74 ~]# chown root:root /home/sftpuser1
[root@rhel74 ~]# chmod 755 /home/sftpuser1
●sftpログイン
[root@rhel74 ~]# sftp com@localhost 成功
[root@rhel74 ~]# sftp sftpuser1@localhost 成功
[root@rhel74 ~]# sftp fal@localhost 成功
[root@rhel74 ~]# sftp nologin@localhost 成功
[root@rhel74 ~]# sftp locked@localhost 失敗
●sshログイン
[root@rhel74 ~]# ssh com@localhost →成功
[root@rhel74 ~]# ssh sftpuser1@localhost →失敗
[root@rhel74 ~]# ssh fal@localhost →失敗
[root@rhel74 ~]# ssh nologin@localhost →失敗
[root@rhel74 ~]# ssh locked@localhost →失敗
●Matchの設定があるため、Subsystemの設定は要らない様なので元に戻す
[root@rhel74 ~]# vi /etc/ssh/sshd_config
Subsystem sftp internal-sftp
↓
Subsystem sftp /usr/libexec/openssh/sftp-server
[root@rhel74 ~]# systemctl restart sshd
●sftpログイン
[root@rhel74 ~]# sftp com@localhost 成功
[root@rhel74 ~]# sftp sftpuser1@localhost 成功
[root@rhel74 ~]# sftp fal@localhost 失敗
[root@rhel74 ~]# sftp nologin@localhost 失敗
[root@rhel74 ~]# sftp locked@localhost 失敗
●sshログイン
[root@rhel74 ~]# ssh com@localhost →成功
[root@rhel74 ~]# ssh sftpuser1@localhost →失敗
[root@rhel74 ~]# ssh fal@localhost →失敗
[root@rhel74 ~]# ssh nologin@localhost →失敗
[root@rhel74 ~]# ssh locked@localhost →失敗