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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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!
Method 2
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 [email protected] 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0