Normal keys are forwarded over the ssh
session, so none of those will work. Instead, use the escape sequences. To kill the current session hit subsequently Enter, ~, ..
(Keep in mind that in international keyboards where ~
is set to be a composing character, you have to hit it twice: Enter, ~, ~, .)
More of these escape sequences can be listed with Enter, ~, ?:
Supported escape sequences:
~. - terminate connection (and any multiplexed sessions)
~B - send a BREAK to the remote system
~C - open a command line
~R - request rekey
~V/v - decrease/increase verbosity (LogLevel)
~^Z - suspend ssh
~# - list forwarded connections
~& - background ssh (when waiting for connections to terminate)
~? - this message
~~ - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)
You can close the list of Escape sequences by hitting Enter.
Notice that because hitting ~~ causes ssh
to send the ~
instead of intercepting it, you can address N nested ssh
connections by hitting ~ N times. (This only applies to ~s that directly follow an Enter.) That is to say that Enter~~~~~. terminates an ssh
session 5 layers deep and keeps the other 4 intact.
"Host key verification failed" means that the host key of the remote host was changed.
SSH stores the host keys of the remote hosts in ~/.ssh/known_hosts
. You can either edit that text file manually and remove the old key (you can see the line number in the error message), or use
ssh-keygen -R hostname
From man page:
-R hostname
Removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed hosts .
(which I learned from the answer to
Is it possible to remove a particular host key from SSH's known_hosts file?).
Best Answer
I have tried this in
/etc/ssh/ssh_config
for Linux and Mac:This is how often, in seconds, it should send a keepalive message to the server. If that doesn't work then train a monkey to press enter every two minutes while you work.
You could set either
ServerAliveInterval
in/etc/ssh/ssh_config
of the client machine orClientAliveInterval
in/etc/ssh/sshd_config
of the server machine. Try reducing the interval if you are still getting the error.Configuration for a single user can be set in file
~/.ssh/config
both on the server and client side. Make sure the file has correct permissionschmod 644 ~/.ssh/config
.