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

  1. Create the home directory for the user.

# mkdir -p /path/to/directory/user

For example:

# mkdir -p /storage/media/myuser
  1. 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
  1. Create the user and specify the home directory.

For example:

  1. Change the file permission and ownership of the home directory.

For example:

  1. Use the ssh-copy-id command to copy the ssh key from the client to the server.

For example:

  1. Apply the correct SELinux security context to the authorized_keys file.

For example:

Verify you can log in successfully.

Last updated