ssh problem
Chris Green
cl at isbd.net
Tue Jun 19 21:08:05 UTC 2012
On Tue, Jun 19, 2012 at 12:54:29PM -0700, rikona wrote:
> Saturday, June 16, 2012, 3:46:14 AM, Chris wrote:
>
> >> What might be happening to ssh? What is the best way to diagnose
> >> this? Best of all, is there a way to keep this from happening? It
> >> has become a PITA. Before the last few updates, I do not recall
> >> this happening. I run 10.04, updated.
> >>
> > It sounds a bit like there's some sort of timeout in the connection.
> > I used to suffer from this when I used ssh to connect through the
> > firewall at work (with permission!). The firewall would drop the
> > connection after several minutes of inactivity. Setting any/all of
> > the keepalive settings in ssh didn't help, I finally resorted to a
> > background script started from .profile which sent a NUL character
> > every few minutes.
>
> I'd be interested in that script...
>
On looking I find it's actually an almost trivial C program, as follows:-
/*
Program to echo NULs periodically
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char * argv[])
{
int delay; // time between outputting NULs
int fd;
char nul[] = { 0 };
switch (argc)
{
case 1:
delay = 600; // default delay of 10 minutes
break;
default:
delay = atoi(argv[1]);
break;
}
while(1)
{
fd = open("/dev/tty", O_RDWR | O_NOCTTY);
if (fd < 0)
{
fd = open("/tmp/kaexit", O_RDWR);
write(fd, "ka exited\n", 10);
exit(1);
}
write(fd, nul, 1);
close(fd);
sleep(delay);
}
}
Then in .profile (or .bash_profile) I have:-
#
#
# Run ka (keep alive) if this is a remote ssh login
#
if [ "$SSH_CLIENT" ]
then ka&
fi
> > The symptoms of the firewall dropping the connection were exactly as
> > you describe, connection stops working but no error message or other
> > symptoms, just silence.
>
> Did terminal stop responding to any input?
>
Yes.
--
Chris Green
More information about the ubuntu-users
mailing list