Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a CentOS 5.7 web server, and I want to change the default place I land in when connecting using SSH.

Currently I land in /home/username, and I want to land in /home instead.

I've gone in as root and added PermitUserEnvironment yes to /etc/.ssh/sshd_config - and as I understand it this then sweeps the user's own ssh folder for an environment file. What I'm not sure about is exactly what I'm adding to this environment file, as export path=$PATH:$HOME doesn't seem to work, either here or in my .bashrc or .bash_profile files (which as I understand it wouldn't make a difference anyway as an SSH connection is a non-interactive shell?).

Thanks in advance.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

If you are using PAM for authentication, which is probably the most likely. As root head into /etc/passwd.

There you should see your username and path! Change it there and you are home free!

EDIT - Sorry it just occurred to me that you maybe didn't want to change your home folder. In that case, simply add:

cd /home

To the bottom of your .bashrc file!

share|improve this answer
    
Thanks! That's done it. –  Ben Feb 23 '12 at 12:33
    
It's better to use usermod when changing anything concerning a user that writes to /etc/passwd, to prevent mistakes: usermod -d /home user. –  laebshade Jan 9 '13 at 2:19

The thing to remember is that ~/.ssh/environment is read before a shell or ssh command is spawned, so (for example) neither export nor $PATH make sense. You can only set environment variables (not run general shell commands) here.

If you grab the environment for a non-interactive ssh shell, then modify that, you should get what you want for non-interactive commands. For example:

$ ssh mylogin@myserver env

will give you what the ssh starts with on your server. If you write your ~/.ssh/environment file as:

PATH=/usr/local/bin

and rerun the above, you should get "bash: env: command not found". Good!

Now, build up your path explicitly, based on what it was at base from your system's sshd (i.e. the first "ssh .... env" call), for example (adding /usr/local/bin at the head):

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Note also that it is not useful to try to set the CWD in ~/.ssh/rc (which is run after ~/.ssh/environment is read, but before your ssh shell or command) as your shell will start (by default) in your home path.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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