You are not logged in.

#1 2008-09-08 15:49:53

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

HOWTO: Closing other SSH sessions

As the title states, how do I close another SSH session? For example, sometimes at home I will accidently leave PuTTY running, and when I get to work and login a second time, accessing certain files with VIM gets complicated because it tries to "auto-recover", when really it is the first session causing the problems. I am looking for a simple command I can call to disconnect the other session. Is this possible? Thanks.

Offline

#2 2008-09-08 15:58:49

Onwards
Member
From: Pakistan
Registered: 2007-04-18
Posts: 108

Re: HOWTO: Closing other SSH sessions

Just kill the other damn session smile

Offline

#3 2008-09-08 16:06:10

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: HOWTO: Closing other SSH sessions

Onwards wrote:

Just kill the other damn session smile

Uh... lol.

I thought this is what I was trying to figure out how to do. Mind explaining how?

Offline

#4 2008-09-08 16:29:22

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: HOWTO: Closing other SSH sessions

Don't bother.  Use screen(1) instead.

Offline

#5 2008-09-08 16:45:29

Bebo
Member
From: Göteborg, Sweden
Registered: 2006-06-07
Posts: 207

Re: HOWTO: Closing other SSH sessions

To kill the connection from the first client when logged on to the server from the second client, you first have to find the sshd process ID (pid) for the first client. Do this by issuing the command netstat -ntp | grep sshd. You need to be root while doing this, to see the sshd process. Locate the line where the fourth column (the "Foreign Address" column) contains the IP of the first client. The last column lists the pid of the corresponding sshd. Now issue kill <sshd pid for the first client>.

If you can log on to the first client from the second client directly, you can just issue killall ssh on the first client.

I do agree with tam1138, though, since I can't really recommend killing another "live" editor, even though vi(m) usually is good at keeping state.

Offline

#6 2008-09-08 17:03:23

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: HOWTO: Closing other SSH sessions

I'm trying to use screen to connect to my remote session, which I see in the list for "netstat -ntp", but I can't figure out how. I read the man page but it isn't very "noob" friendly. I tried "screen -r [process id]", and it does not work.

Below is the result of my netstat command:

robert ~/subversion $ sudo netstat -ntp
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 192.168.10.150:22       96.226.60.136:7012      ESTABLISHED 29446/sshd: robert
tcp        0    336 192.168.10.150:22       75.55.7.44:3151         ESTABLISHED 29458/sshd: robert

The second entry is the connection I'm currently using. The first entry is the session I want to close. From previous posts in this thread, I want to use screen to "take over" that session and exit it normally like I would do if I physically went home and did it through that particular PuTTY session.

PS: Random question... what does -t do in netstat? I saw no mention of this in the manpages for netstat.
PSS: What is tty? I saw this mentioned in the man pages for 'screen'

Last edited by void.pointer (2008-09-08 17:07:04)

Offline

#7 2008-09-08 18:15:45

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: HOWTO: Closing other SSH sessions

screen won't help you kill an existing editor session.  But in the future, you should first start screen and run your editor inside it, so you can resume the editor when you reconnect elsewhere.  There are more than a few potentially promising results when googling "screen tutorial".

The -t option to netstat limits output to TCP connections only.

Offline

#8 2008-09-08 18:38:18

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: HOWTO: Closing other SSH sessions

tam1138 wrote:

screen won't help you kill an existing editor session.  But in the future, you should first start screen and run your editor inside it, so you can resume the editor when you reconnect elsewhere.  There are more than a few potentially promising results when googling "screen tutorial".

The -t option to netstat limits output to TCP connections only.

So then it would be wise to configure archlinux to run in 1 instance of screen to begin with (when connecting in via ssh), versus the default right now? I'll see if I can do some research to figure out how to do this.

Offline

#9 2008-09-08 19:56:08

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: HOWTO: Closing other SSH sessions

It would be simple to add a screen launcher to your bashrc. Just add "screen -DRR"

Offline

#10 2008-09-08 20:08:50

void.pointer
Member
From: Dallas, TX
Registered: 2008-07-30
Posts: 239

Re: HOWTO: Closing other SSH sessions

Oh wow, now when I login, I get this:

login as: ****
*****@******'s password:
Last login: Mon Sep  8 14:55:35 2008 from 75.55.7.44
LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:';
export LS_COLORS
LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:';
export LS_COLORS
Attaching from inside of screen?

Here is my .bashrc:

  1 alias ls='ls --color=auto'
  2 PS1='\[\e[1;36m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] '
  3 #PS1='[\u@\h \W]\$ '
  4 #export LC_CTYPE=en_US.utf8
  5 #export LC_ALL=en_US.iso88591
  6 #export LC_LANG=en_EN.utf8
  7 export PATH=$PATH:/usr/local/bin
  8
  9 eval 'dircolors -b .dir_colors'
 10 screen -DRR

Anything I'm missing?

Last edited by void.pointer (2008-09-08 20:09:34)

Offline

Board footer

Powered by FluxBB