Unlike bash
, ssh
's password prompt doesn't use any special terminal-input library like readline
. The line-editing features are just the baseline POSIX TTY line-editing features.
So you have a POSIX TTY in "cooked" mode (not raw), aka canonical mode, and the only line editing that's available is what's provided by the kernel. See stty(1)
, and notice that
kill = ^U
. This is also where the backspace character is defined (erase = ^?
). Word-erase (^W
) is convenient when you're not typing blind.
lnext = ^V
means you can type control-v then anything (including control-c) to get a literal control-c.
To debug what you were trying to do blindly, run cat
or cat > /dev/null
in your terminal. Type stuff, then see what works and what doesn't to edit it.
readline
(used by bash
) reads raw character and does the line-editing in user-space. Its default bindings are compatible with the default TTY control characters, though, for the subset of editing features that they both provide.
readline goes way beyond the simple line editing of a plain TTY. (e.g. a TTY can only delete characters at the end of the line, so there's no ^a
and delete
or left/right arrow)
When bash
runs a command in the foreground, it puts the TTY into canonical mode first (because that's the default). So running stty -a
(with no redirection) will always see its own terminal in canonical mode. But if you redirect input from some other TTY that has bash
running on it, you can see what terminal settings bash + readline applied. e.g. stty -a < /dev/pts/12
shows -icanon
for raw mode because I have a bash
running on that terminal. (I switched to another tab and ran tty
, then used that device file path from the first terminal). If I ran cat
in that other terminal, I'd see icanon
for canonical mode.
Related: The TTY demystified
https://www.gnu.org/software/libc/manual/html_node/Canonical-or-Not.html
https://en.wikipedia.org/wiki/POSIX_terminal_interface
7Regarding Ctrl+A, in the terminal this usually means "go to start of line". The set of keys used in the terminal (especially bash) is often closer to Emacs than to Windows. – Score_Under – 2017-11-01T14:20:07.607
18Sshing as root is generally considered a very very bad practice. – Sam – 2017-11-01T15:18:18.553
To delete characters from the screen, you will need to use cursor control sequences (if your terminal supports them). By running
ssh
from a script, you can analyse the parameter string before you run it. – AFH – 2017-11-01T15:25:05.0704Please pay attention to what @Sam told. You should disable root logins everywhere. Log in as a regular user with a complicated password and then
su
to become root. The next step is to disable password-based authentication schemes in SSH and use keys for login. – kostix – 2017-11-02T08:29:32.367@kostix I'm pretty sure disabling passwords should be the first step. If you are using passwords, then with su and disabled root, it's just a matter of entering the password which the attacker already guessed a second time after login, so you only gain something if the user name is hard to guess (which it often isn't, I assume without having statistics). And without password login it adds a second secret, the password, but this is worth less than the private key which is a longer secret. – Nobody – 2017-11-03T17:17:04.470
@Sam I remember I had an installation once where I bypassed my router and enabled root access via ssh with a dictionary password. Within a couple weeks, someone online had hijacked my PC. You live, you learn... – sig_seg_v – 2017-11-04T00:38:55.307
@Sam: Not with public key authentication (and passwords disabled). – user541686 – 2017-11-04T19:37:46.763