Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the most gentle way to end a ssh session [closed]

Tags:

linux

bash

ssh

So far, I already know there are many ways to end a ssh session and disconnect from remote server. Assume under the environment of bash.

  • Bash built-in command exit

    $ exit

  • Bash built-in command logout

    $ logout

  • Keyboard shortcut Control + D
  • External command fuser

    $ fuser -k /dev/pts/[n]

  • Get sshd process id for current user then kill this process

Can anyone explain what's the difference between these commands? Personally Ctrl + D is my favorite one, because it's the fastest one.

like image 255
alijandro Avatar asked Dec 22 '14 07:12

alijandro


People also ask

How do I end an SSH session?

In that case, you can type ~. to close the SSH session and return to your local command line terminal. This works as an escape character for SSH connections.

How do I end a SSH session in putty?

To end the Putty session, type the logout command such as exit or logout. This command might vary between servers. You can close the session by using the Close button.

Which command is stopped after SSH logout?

disown will keep the process running after you log out. The -h flag prevents hangup. screen and others can do it, but that's not what they're for.


1 Answers

CTRL + d causes a logout. logout causes an exit. exit on its own is different only because it allows you to specify a non-zero exit code in case it's needed. So the first 3 options are equivalent.

Killing ssh, or the terminal will just break the connection. I'm not sure what you're going for with "gentle", but that is not it.

Assuming that by gentle you meant closing connections without errors on either side, just keep using CTRL + d

like image 193
viraptor Avatar answered Sep 21 '22 13:09

viraptor