My problem is, that I have to set env variables (like GIT_EXEC_PATH) on a server. I need that variables by every connection (so by bash and by remote commands either). I managed to set those variables by bash with .bash_profile, but I have problems with the remote commands. I found that it’s possible to write commands in ~/.ssh/authorized_keys before the actual rsa key, but I don’t wan’t to write there always, I need a permanent solution… I found that the ~/.ssh/rc file is executed by every ssh login, so I put there my env variable declarations, but it didn’t work. The variables are set in the rc file, but after that they disappeared. :S Maybe the rc file runs in a subshell :S Is there any way to define those variables in bash and in remote commands without code duplication?
Edit:
I edited the question, because the server is a godaddy shared host, so it has a unique config. The /etc/ssh/sshd_config and the /etc/ssh/ssh_config files are empty. There are comments in those files, if you are curious I can copy it here.
- The ~/.bash_profile is sourced (by bash connections only),
- the ~/.bashrc is never sourced,
- the ~/.profile is never sourced,
- the ~/.ssh/environment is never sourced,
- the ~/.ssh/rc is sourced (by bash and remote both), but I think it’s
called in subshell, because the variables disappearing. - The ~/.ssh/authorized_keys is sourced by every time, but I have to
write the commands before every rsa key (so I don’t wan’t to
configure with that).
Summary:
I can configure the bash well (with .bash_profile), but I cannot configure the remote calls. That’s the problem. I’m looking for a file which is sourced by both bash and remote commands.
For example:
The git-upload-pack command finds the exe file, because the GIT_EXEC_PATH env variable is set, but with remote: “git clone user@domain.com:myrepo local/myrepo” the server doesn’t find that command, because the GIT_EXEC_PATH is not set.
Edit2:
According to this, and my printenv logs: the ~/.ssh/rc is running in normal shell, not in subshell, so it’s a riddle why the env variables not sticking…
I created an executable: ~/logenv:
echo "" >> mylog.txt
date >> mylog.txt
printenv >> mylog.txt
echo "" >> mylog.txt
And put this into the ~/.ssh/rc:
export AAA=teszt
source ~/logenv
By bash login & “source logenv” the result was:
Tue May 15 04:21:37 MST 2012
TERM=cygwin
SHELL=/bin/bash
SSH_CLIENT=censored
SSH_TTY=/dev/pts/2
USER=myuser
AAA=teszt
MAIL=/var/mail/myuser
PATH=/usr/local/bin:/bin:/usr/bin
PWD=/home/content/65/7962465
SHLVL=3
HOME=/var/chroot/home/content/65/7962465
LOGNAME=myuser
SSH_CONNECTION=censored
_=/usr/bin/printenvTue May 15 04:21:41 MST 2012
HOSTNAME=censored
TERM=cygwin
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=censored
By remote “ssh myuser@domain.com ‘exec ~/logenv'” the result was:
Tue May 15 04:25:52 MST 2012
SHELL=/bin/bash
SSH_CLIENT=censored
USER=myuser
AAA=teszt
MAIL=/var/mail/myuser
PATH=/usr/local/bin:/bin:/usr/bin
PWD=/home/content/65/7962465
SHLVL=3
HOME=/var/chroot/home/content/65/7962465
LOGNAME=myuser
SSH_CONNECTION=censored
_=/usr/bin/printenvTue May 15 04:25:52 MST 2012
SHELL=/bin/bash
SSH_CLIENT=censored
USER=myuser
PATH=/usr/local/bin:/bin:/usr/bin
MAIL=/var/mail/myuser
PWD=/home/content/65/7962465
HOME=/var/chroot/home/content/65/7962465
So the rc file is sourced, but after that the variables disappering… :S
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="~/connect.sh" ssh-rsa AAAAB3NzaC...
In the ~/connect.sh:
#!/bin/bash
if [ -f "${HOME}/.env_profile" ]; then
source ~/.env_profile
fi;if [ "x${SSH_ORIGINAL_COMMAND}x" == "xx" ]; then
$SHELL --login
else
eval "${SSH_ORIGINAL_COMMAND}"
fi;
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. (This will be the accepted answer until somebody gives a working solution without code duplication.)
Check more discussion of this question.