2

This is a follow up from this question:

https://askubuntu.com/questions/563828/how-to-change-my-home-directory?noredirect=1#comment775654_563828

The summary is:

  • running ubuntu 14.04
  • ssh'ing into it ssh -X user@host end up in bash session
  • I want to change my home directory from the /current/home/ to the /new/home/ which already exists

I thought of adding the following line to be executed upon login:

export HOME=/new/home

The files that exist in the /current/home/ I thought might be relevant are:

  • .login
  • .profile

When I add that command in the .profile file it works.

I would ideally like it to be in the file that is run first so that everything run after have the correct HOME variable set.

I don't have root access or access through another user on the remote machine.

3

I had exactly the same problem before. In my case we had multiple users which (for political reasons) had to share the same user account which gets messy if different people want different preferences or expect their own command history.

The solution was to create an own home directory for each real user and change HOME at login time.

To do this I used ssh keys, put the public key into .ssh/authorized keys and used a forced command there to start a small shell script which set the new home and start a new shell or ran SSH_ORIGINAL_COMMAND if specified.

In .ssh/authorized key write something like

command="/home/me/bin/startupscript" ssh-rsa ...

and in startupscript write something like

env -i HOME=/new/home ${SSH_ORIGINAL_COMMAND:-bash -l}

supporting SSH_ORIGINAL_COMMAND is important for things like scp, which will now also use the new home.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.