Eric Stillwagon Eric Stillwagon - 4 months ago 22
Linux Question

ssh connections are spawning hundreds of ssh-agent /bin/bash instances

I have an Arch server running on a VMWare VM. I connect to it through a Firewall that forwards ssh connections from port X to port 22 on the server. Yesterday, I started receiving the error "Bash: Fork: Resource Temporarily Unavailable". I can log in as root and manage things without problem, but it seems that when I ssh in as the user I normally use, the ssh session is now spawning hundreds of ssh-agent /bin/bash sessions. This is, in turn, using up all the threads and file descriptors (from what I can tell) on the system and making it unusable. The little bit of info I've been able to find thus far tells me that I must have some sort of loop, but this hasn't happened until yesterday, possibly when I ran updates. At this point, I am open to suggestions.

Answer

One of your shell initialization files is probably spawning a shell, which, when reading the shell initialization files will spawn a shell, etc.

You mentioned ssh-agent /bin/bash. Putting this in .bashrc will definitely cause problems, as this instructs ssh-agent to spawn bash...

Instead, use something like

if [[ -z "$SSH_AUTH_SOCK" ]]; then
  eval $(ssh-agent)
fi

in .bashrc (or .xinitrc or .xsession for systems with graphical logins).

Or possibly (untested):

if [[ -z "$SSH_AUTH_SOCK" ]]; then
  ssh-agent /bin/bash
fi

in .bash_profile.

Comments