When working with GoDaddy's shared hosting environment, many developers face a frustrating issue: environment variables set during SSH connections don't persist between sessions. This becomes particularly problematic when trying to configure tools like Git that rely on specific environment paths (e.g., GIT_EXEC_PATH).
GoDaddy's shared hosting has some unique characteristics that affect how environment variables are handled:
- /etc/ssh/sshd_config and /etc/ssh/ssh_config are empty (only contain comments)
- ~/.bash_profile is only sourced for interactive bash sessions
- ~/.bashrc and ~/.profile are never sourced
- ~/.ssh/environment isn't processed
- ~/.ssh/rc executes but variables disappear after execution
Through testing with a logging script, we can see the environment variables are indeed set in ~/.ssh/rc but don't persist. This suggests the SSH daemon on GoDaddy's shared hosting is configured to clean the environment after processing the rc file.
# Sample logging script (~/logenv)
echo "" >> mylog.txt
date >> mylog.txt
printenv >> mylog.txt
echo "" >> mylog.txt
1. Forced Sourcing via ~/.ssh/rc
While not ideal, you can force the sourcing of your variables in every command:
# ~/.ssh/rc
if [ -n "$SSH_ORIGINAL_COMMAND" ]; then
# For non-interactive commands
export GIT_EXEC_PATH=/path/to/git/exec
eval "$SSH_ORIGINAL_COMMAND"
else
# For interactive sessions
export GIT_EXEC_PATH=/path/to/git/exec
fi
2. Wrapper Script Approach
Create a wrapper script that sets the environment before executing commands:
# ~/bin/git-wrapper
#!/bin/bash
export GIT_EXEC_PATH=/path/to/git/exec
/usr/bin/git "$@"
Then configure ~/.ssh/authorized_keys to use this wrapper:
command="~/bin/git-wrapper" ssh-rsa AAAAB3NzaC1yc2E... user@host
3. Combined Profile and RC Solution
A more comprehensive approach that works for both interactive and non-interactive sessions:
# ~/.bash_profile
if [ -f ~/.bashenv ]; then
. ~/.bashenv
fi
# ~/.ssh/rc
if [ -f ~/.bashenv ]; then
. ~/.bashenv
fi
# ~/.bashenv (common environment file)
export GIT_EXEC_PATH=/path/to/git/exec
export PATH=$PATH:/additional/paths
For Git specifically, you might need to modify how Git commands are processed:
# ~/bin/git-shell-commands
#!/bin/bash
export GIT_EXEC_PATH=/path/to/git/exec
case "$SSH_ORIGINAL_COMMAND" in
"git-upload-pack"*)
exec git-upload-pack "${SSH_ORIGINAL_COMMAND#git-upload-pack }"
;;
"git-receive-pack"*)
exec git-receive-pack "${SSH_ORIGINAL_COMMAND#git-receive-pack }"
;;
*)
echo "Access denied"
exit 1
;;
esac
Setting persistent environment variables across all SSH connection types (interactive shells and remote commands) on GoDaddy's shared hosting proves particularly challenging due to their custom configuration. The standard approaches fail because:
- /etc/ssh/sshd_config and /etc/ssh/ssh_config are empty
- ~/.bashrc and ~/.profile are never sourced
- ~/.ssh/environment is ignored
- ~/.ssh/rc executes but variables don't persist
Through testing with a logging script (~/logenv):
#!/bin/bash
echo "" >> envlog.txt
date >> envlog.txt
printenv >> envlog.txt
We observe that while ~/.ssh/rc executes and sets variables temporarily, they disappear immediately after execution. This suggests the SSH daemon on GoDaddy's shared hosting performs some environment cleaning between the rc execution and the actual command/shell startup.
1. Force-Executing Profile Script
Modify ~/.ssh/rc to forcibly source your profile:
#!/bin/bash
# Force source bash profile
[ -f ~/.bash_profile ] && . ~/.bash_profile
2. AuthorizedKeysCommand Wrapper
Create a wrapper script (e.g., ~/ssh_wrapper):
#!/bin/bash
export GIT_EXEC_PATH=/path/to/git/exec
export OTHER_VARS=values
exec "$@"
Then prepend each line in ~/.ssh/authorized_keys with:
command="~/ssh_wrapper" ssh-rsa AAAAB3NzaC1yc2E...
3. Remote Command Prefixing
For Git operations, modify your local Git config:
git config remote.origin.uploadpack "GIT_EXEC_PATH=/path /path/to/git-upload-pack"
git config remote.origin.receivepack "GIT_EXEC_PATH=/path /path/to/git-receive-pack"
Forcing Environment Through SSH Client
Modify your local ~/.ssh/config:
Host godaddy
HostName yourdomain.com
SendEnv GIT_EXEC_PATH
RemoteCommand export GIT_EXEC_PATH=/path && exec $SHELL
Persistent Environment via Screen/Tmux
For interactive sessions, launch a persistent session:
ssh user@host "screen -AmdS env_session bash -c 'export GIT_EXEC_PATH=/path; exec bash'"
ssh -t user@host "screen -r env_session"
The most reliable solution for GoDaddy's constrained environment appears to be the authorized_keys command wrapper approach, despite its maintenance overhead. For Git specifically, the remote command configuration provides a cleaner alternative.