Set Default Home directory for all users, as admin

How can i configure the environment variable that would set the default home directory of each user at the beginning of a session ? For example, with 'aleks' user, connecting on rstudio server :

HOME="/data/users/${username}"

The session of the user would start in the /data/users/aleks directory.

I'm looking for a "dynamic" solution like this. Thank you.

In my situation, rstudio-server pro is installed on centos 7.

1 Like

This is a fantastic question! Likewise, I am always tempted to munge the HOME variable. However, this is actually stored elsewhere in the definition of a user. As a result, your best bet is to change that underlying source.

If your server is joined to a domain (Active Directory or LDAP), then LDAP servers allow defining the home directory and tools like sssd allow overriding it.

In other cases (e.g. local accounts), it is better to just change the definition of a user. This is defined when the user is created, and is stored in /etc/passwd for local accounts. You can explore the values using:

getent passwd myuserid

You should notice the second to last value is the user's home directory.

Then if you want to change it, you can use the usermod command. This is discussed in more detail here:

IMPORTANT NOTE: Do not change a home directory of your main user account before testing. If you do so and log out of a server that requires SSH access, you may not be able to authenticate (SSH keys are stored in ~/.ssh and changing the home directory can cause problems with resolving that path).

Another NOTE: Although it may be desirable to have a different home directory for RStudio Server and the underlying operating system, this is not recommended. RStudio Server interfaces very closely with the underlying linux operating system, so whatever home directory a user has should be consistent for the OS and for RStudio Server.

Hope that helps! You may need to start a new shell to pick up the new home directory. See tmux for wizardry here that can help avoid the danger above :slight_smile: Multiple shells in a single session!