Ubuntu – Kill ssh process

pidsshUbuntu

I was connected to an ubuntu machine and instead of typing exit to logout, I killed the ssh process by its PID:

kill PID

Now, when I try to connect again to the ubuntu machine, I get the following error message:

Connection closed by xx.xxx.xxx.xx port 22

Where the x represent the machine's address. Did I do something wrong? Why can't I connect to the machine anymore? Note that I am writing a bash script that connects to the server, runs some commands and then terminates the connection to the server, so that's why I killed the ssh process instead of manually logging out.

PS: I'm using a Mac.

Best Answer

Any particular reason you don't run "exit" command instead? That will close your ssh session gracefully.

e.g.

ssh user@remotehost
exit

You could also execute command like this: ssh user@remotehost "ls -l"

This command will effectively list the contents of user's home directory on the remote host, return the output to your console and exit automatically.

"ls -l" - is used as an example of the command you want to execute on the remote host.

The message you are getting make sense, as it looks like you are killing SSHD process/service on the machine you were connected to. As a result of your actions, SSHD process is not running, thus port TCP22 is not listening on your remote machine.

Related Topic