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?
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).
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.
The git-upload-pack command finds the exe file, because the GIT_EXEC_PATH env variable is set, but with remote: "git clone firstname.lastname@example.org:myrepo local/myrepo" the server doesn't find that command, because the GIT_EXEC_PATH is not set.
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/printenv Tue May 15 04:21:41 MST 2012 HOSTNAME=censored TERM=cygwin SHELL=/bin/bash HISTSIZE=1000 SSH_CLIENT=censored
By remote "ssh email@example.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/printenv Tue 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