SSH - set env vairables by every connection - godaddy shared host

Solution 1:

Assuming you have UsePAM yes in /etc/ssh/sshd_config, and assuming you want these environment variables set for every user, you can have pam set environment variables for you. If you have the environment variables defined in /etc/gitenv you could add this line to /etc/pam.d/sshd

auth required envfile=/etc/gitenv

Or by inpsecting this file, you might find that there is already a being used, and already a file you can add stuff to. Just be careful, and make sure you have thoroughly tested your changes before ending your ssh session, as when you are messing with pam, you can completely break your ability to login to your server, if you are not careful.

Solution 2:

I'm setting some environment variable for my SSH connections using the ~/.ssh/environment. The file can contain variable in the form VAR=value, no need to explicitly export them.

However, this user configuration file is ignored by default by the SSH server process unless the option PermitUserEnvironment is set to yes. Therefore you need to make sure to edit /etc/sshd_config on the SSH server to add or update this parameter:

PermitUserEnvironment yes

You need to reload the SSH server configuration. On RHEL or Suse Linux you do (as root)

/sbin/service sshd reload

(Possibly replace sshd by ssh if it does not work)

On Ubuntu (using upstart) you do

sudo reload ssh

On any other Linux, you could try (as root)

/etc/init.d/sshd reload

(Replace sshd by ssh or openssh or whatever that would correspond to the SSH server init script)

Solution 3:

I have no longer a godaddy shared host, so I cannot check whether the proposed solutions are valid. This will stay the accepted answer, since it worked by me when I asked the question. The other answers might work as well. I let the community decide that with upvotes.

Ok. The solution is that there is no solution on a godaddy shared host. I tried everything, but nothing works, so I decided that I stay with the ~/.ssh/authorized_keys:

command="~/" ssh-rsa AAAAB3NzaC...

In the ~/

if [ -f "${HOME}/.env_profile" ]; then
        source ~/.env_profile

if [ "x${SSH_ORIGINAL_COMMAND}x" == "xx" ]; then
        $SHELL --login
        eval "${SSH_ORIGINAL_COMMAND}"

And in the ~/.env_profile:

export PATH=$PATH:$HOME/bin:$HOME/git/libexec/git-core
export LD_LIBRARY_PATH=$HOME/git/lib
export GIT_EXEC_PATH=~/git/libexec/git-core
export GIT_TEMPLATE_DIR=~/git/share/git-core/templates

So I have to copy the command="..." to every rsa key in the authorized_keys. This is code duplication, but I don't think there is another solution on a godaddy shared hosts.