Score:0

SSH with "Do not execute a remote command" hangs

tt flag

I have Ubuntu 22.04 installed on a remote server. I can ssh to the server without any issues.

I often need to open a vnc tunnel with the following command:

ssh -L 5901:127.0.0.1:5901 -C -N -l username ip.add.re.ss

Sadly, including the option "-N", in other words "Do not execute a remote command" causes the connection to hang.

I am still requested to provide the passphrase for the RSA key, but once captured, nothing happens.

Removing -N works perfectly, but it does not serve the purpose in terms of security.

Happy to hear some ideas, as this is rather perplexing.

Here is the verbose output.

OpenSSH_8.6p1, LibreSSL 3.3.6
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to my.ip.add.res [my.ip.add.res] port 22.
debug1: Connection established.
debug1: identity file /Users/user/.ssh/id_rsa type 0
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: identity file /Users/user/.ssh/id_dsa type -1
debug1: identity file /Users/user/.ssh/id_dsa-cert type -1
debug1: identity file /Users/user/.ssh/id_ecdsa type -1
debug1: identity file /Users/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/user/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/user/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/user/.ssh/id_ed25519 type -1
debug1: identity file /Users/user/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/user/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/user/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/user/.ssh/id_xmss type -1
debug1: identity file /Users/user/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3
debug1: compat_banner: match: OpenSSH_8.9p1 Ubuntu-3 pat OpenSSH* compat 0x04000000
debug1: Authenticating to my.ip.add.res:22 as 'user'
debug1: load_hostkeys: fopen /Users/user/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: zlib@openssh.com
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: zlib@openssh.com
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:XrQBKNemfjR4C9Yfuzc12jWk0n8yQPxUNdyhsmRRBSg
debug1: load_hostkeys: fopen /Users/user/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'my.ip.add.res' is known and matches the ED25519 host key.
debug1: Found key in /Users/user/.ssh/known_hosts:16
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/user/.ssh/id_rsa RSA SHA256:FC8EntXzlysgFHBl8JkM1WAG+8MmaQbrkW64oA8D1Lc
debug1: Will attempt key: /Users/user/.ssh/id_dsa 
debug1: Will attempt key: /Users/user/.ssh/id_ecdsa 
debug1: Will attempt key: /Users/user/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /Users/user/.ssh/id_ed25519 
debug1: Will attempt key: /Users/user/.ssh/id_ed25519_sk 
debug1: Will attempt key: /Users/user/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com>
debug1: kex_input_ext_info: publickey-hostbound@openssh.com (unrecognised)
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/user/.ssh/id_rsa RSA SHA256:FC8EntXzlysgFHBl8JkM1WAG+8MmaQbrkW64oA8D1Lc
debug1: Server accepts key: /Users/user/.ssh/id_rsa RSA SHA256:FC8EntXzlysgFHBl8JkM1WAG+8MmaQbrkW64oA8D1Lc
Enter passphrase for key '/Users/user/.ssh/id_rsa': 
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (publickey).
Authenticated to my.ip.add.res ([my.ip.add.res]:22).
debug1: Local connections to LOCALHOST:5901 forwarded to remote address 127.0.0.1:5901
debug1: Local forwarding listening on ::1 port 5901.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 5901.
debug1: channel 1: new [port listener]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem full
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: client_input_hostkeys: searching /Users/user/.ssh/known_hosts for my.ip.add.res / (none)
debug1: client_input_hostkeys: searching /Users/user/.ssh/known_hosts2 for my.ip.add.res / (none)
debug1: client_input_hostkeys: hostkeys file /Users/user/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: no new or deprecated keys from server
debug1: Remote: /home/user/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
debug1: Remote: /home/user/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
dummyuser avatar
uy flag
Looks like this is the expected behaviour. You can not execute a command, but the ssh session is established and port forwarding works. `ssh -L a.b.c.d:8081:e.f.g.h:22 -C -N e.f.g.h` and `nc a.b.c.d 8081 -v` Output: `Connection to a.b.c.d 8081 port [tcp/tproxy] succeeded! SSH-2.0-OpenSSH_8.9p1 Ubuntu-3`
Mac Technicon avatar
tt flag
Sadly, this is not what happens. There is no "success" message, just a cursor: `user@MacBook-Pro ~ % ssh -L 5901:127.0.0.1:5901 -C -N -l username my.ip.add.res Enter passphrase for key '/Users/user/.ssh/id_rsa': _`
FedKad avatar
cn flag
Please, [edit] your question and add the output of your command with the `-v` option appended.
Mac Technicon avatar
tt flag
@FedKad, I have just added the output with -v
Score:0
fr flag

Try the -T flag to request a terminal. Or if you're ok with creating an ssh config for this connection you can try using the RequestTTY yes flag. https://www.computerhope.com/jargon/r/requesttty.htm

Mac Technicon avatar
tt flag
Adding -T flag did not change the output. I will have a look at the RequestTTY option, thank you!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.