How to create a chroot sftp user with logging on a non-standard home directory
Environment
Red Hat Enterprise Linux
openssh
Issue
How to configure chroot sftp users with logging with a non-standard home directory.
Resolution
Create the chroot directory including the user's home directory.
# mkdir -p /path/to/directory/user/homeFor example:
# mkdir -p /storage/media/myuser/homeIn this example, home was used for the name of the directory under the username, but this subdirectory can be named whatever you want.
For example:
# mkdir -p /storage/media/myuser/uploadsCreate the user and specify the newly created home directory.
# useradd -d /path/to/directory/user/home -M username
# passwd usernameFor example:
Apply the correct
SELinuxsecurity context to the home directory.
For example:
Create a
/devdirectory in the user directory.
For example:
Change the ownership and permissions of the home directory.
For example:
Because of the requirements of chroot, all directories except for the home directory need to be owned by root.
For example:
If you use a different directory besides home, the same ownership and permissions apply.
Use the
ssh-copy-idcommand to copy thesshkey from a client to the server.
For example:
Apply the correct
SELinuxsecurity context to the.sshdirectory.
For example:
Create an entry in the
/etc/rsyslog.conffile to create the log file for the user.
For example:
Run the bind option of the
mountcommand.
For example:
Apply the correct
SELinuxlabel to the log file.
For example:
Edit the
/etc/ssh/sshd_configfile and add aMatchsection for the user:
For example:
Enable the
SELinuxboolean for ssh chroot.
Restart
rsyslogandsshd.
Last updated