How to create a user with a non-standard home directory
Environment
Red Hat Enterprise Linux
openssh
Issue
How to create an
SSH
user with a non-standard home directory.
Resolution
Create the home directory for the user.
# mkdir -p /path/to/directory/user
For example:
# mkdir -p /storage/media/myuser
Apply the correct
SELinux
label.
# chcon -Rv --type=user_home_dir_t /path/to/directory/user
For example:
# chcon -Rv --type=user_home_dir_t /storage/media/myuser
Create the user and specify the home directory.
# useradd -d /path/to/directory/username -M username
# passwd username
For example:
# useradd -d /storage/media/myuser -M myuser
# passwd myuser
Change the file permission and ownership of the home directory.
# chown -R user:user /path/to/directory/user
# chmod 700 /path/to/directory/user
For example:
# chown -R myuser:myuser /storage/media/myuser
# chmod 700 /storage/media/myuser
Use the
ssh-copy-id
command to copy thessh
key from the client to the server.
$ ssh-copy-id user@ip_address
For example:
$ ssh-copy-id [email protected]
Apply the correct
SELinux
security context to theauthorized_keys
file.
# chcon -R -v system_u:object_r:usr_t:s0 /path/to/directory/username/.ssh/authorized_keys
For example:
# chcon -R -v system_u:object_r:usr_t:s0 /storage/media/myuser/.ssh/authorized_keys
Verify you can log in successfully.
$ ssh [email protected]
Last login: Fri Sep 29 16:19:37 2023 from 192.0.2.33
[myuser@example ~]$
PreviousConfigure Ubuntu 22.04 as a DNS server using ControlDNextHow to create a chroot sftp user with logging on a non-standard home directory
Last updated