I want to use Git over SSH with my Linode VPS running Ubuntu 10.04 LTS.

Instructions seem pretty easy, in fact given I had already setup my SSH key etc..

All I had to do was instruct my local repository to send to the server


Problem is when I do git push origin master it just stall, no network activity, no errors, after a few minutes I kill it with Ctrl-C. I sent along time yesterday try to diagnosis the problem. So on the server I setup a new user matt2 and copied authorized_keys across to matt2 and tried pushing to matt2@myvps.com:22 and viola it worked.

What are differences between matt and matt2? Well matt has this in his .bash_profile to ensure an ssh-agent is running (i need this func alot):

# Start/Reuse SSH Agent - restart or re-use an existing agent
if [ -s "${SSH_AGENT_CACHE}" ]
    echo "Reusing existing ssh-agent"
    eval `cat "${SSH_AGENT_CACHE}"`
    # Check that agent still exists
    kill -0 "${SSH_AGENT_PID}" 2>-
    if [ $? -eq 1 ]
        echo "ssh-agent pid ${SSH_AGENT_PID} no longer running"
        # Looks like the SSH-Agent has died, it'll be restarted below
        rm -f "${SSH_AGENT_CACHE}"

if [ ! -f "${SSH_AGENT_CACHE}" ]
    echo "Starting new ssh-agent"
    touch "${SSH_AGENT_CACHE}"
    chmod 600 "${SSH_AGENT_CACHE}"
    ssh-agent >> "${SSH_AGENT_CACHE}"
    chmod 400 "${SSH_AGENT_CACHE}"
    eval `cat "${SSH_AGENT_CACHE}"`

So it appears my .bash_profile conflicts with the operating of git over SSH. Any suggestions of workarounds?

I don't want to use 2 user accounts, and I want to keep my .bash_profile. It would be good if I could edit the .bash_profile and wrap the functionality around if [ $connectingWith != "git-client" ] but I doubt such thing exists?



I'm pretty sure the problem is that your .bashrc is echoing stuff. Never print anything from .bashrc when it's not running on a terminal, as this will break programs that use ssh for automated actions (rsync, git, …).

In fact, you shouldn't do anything from .bashrc if it's not running on a terminal. Put this at the beginning of the file:

if ! [ -t 1 ]; then return; fi

The .bashrc file is intended for interactive shells. There's a quirk in bash that makes it load this file for all rsh and ssh logins, regardless of whether they're interactive. This is occasionally useful because it lets you set environment variables for a non-interactive ssh session, but that's completely different thing from interactive setup (prompt, key bindings, aliases and so on). In full generality, .bashrc can be two unrelated sections:

if [ -t 1 ]; then
  # Stuff for interactive bash shells (defined here as shells running in a terminal).
  # Prompt, key bindings, aliases, terminal settings, …
  # It's ok to print things to the terminal here (e.g. to set the terminal title).
  # Environment variables for ssh sessions.
  # Do not print anything here.

Side note: for an interactive ssh login, if bash is your login shell, it reads .bash_profile but not .bashrc. You'll want to source .bashrc in your .bash_profile (if the shell is interactive).


Please ignore. There was something in .bashrc which was causing problems. I didnt see this as this was not executed when SSH in.

  • 4
    Don't leave us hanging! If you think this could be useful for other people, tell us what in your .bashrc was causing the problem and how you solved it. If you think the problem is so specific to your setup that there's no point in having the question and answer on the web, delete them. – Gilles Mar 8 '11 at 18:45
  • Yes... add here your solution to your question. It might help someone. – txwikinger Mar 9 '11 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.