Eric Stillwagon Eric Stillwagon - 1 year ago 87
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 Source

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)

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

Or possibly (untested):

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

in .bash_profile.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download