16

I would like to setup one of the SSH connections in my ssh_config file to use the -N ssh flag. I can't find any matching config keyword for this parameter. I'm using the connection for port forwarding only and I would like it to use -N every time I execute ssh host. I'm using mosh for the interactive shell.

-N      Do not execute a remote command.  This is useful for just forwarding ports (protocol version 2 only).

3 Answers 3

5

Being a fairly prominent result in Google, this is still worth answering 11 years later:

Host example
    HostName     example.com
    SessionType  none

SessionType was introduced in OpenSSH 8.7, released in 2021-08-20, in this commit:

add a SessionType directive to ssh_config, allowing the configuration file to offer equivalent control to the -N (no session) and -s (subsystem) command-line flags.

4
  • 1
    Thanks for adding this answer! FWIW, it was me who fixed this issue, provided a patch to OpenSSH, went though several review rounds, eagerly awaited the Debian package ... but finally forgot to add it in this ServerFault question as an answer. See also: njh.eu/openssh
    – vog
    Feb 5 at 11:37
  • @vog: Nice! Well done, and thank you for that patch, it's is very handy! No more aliasing ssh -nNT :)
    – MestreLion
    Feb 5 at 22:27
  • @vog btw, what software you used for the blogger-like at njh.eu ? I liked its simplicity, and currently looking for self-hosting blogger apps to my homelab)
    – MestreLion
    Feb 5 at 22:39
  • MestreLion: It is a simple, hand-written XSLT script. Feel free to approach me via email if you want to know more.
    – vog
    Feb 7 at 13:20
4

I don't know about mosh, but for the OpenSSH client you can specify a ProxyCommand in the config file. The relevant entry for hostname foobar.baz.edu (my favorite university) and dynamic forwarding of port 9999 would be:

Host FooBar
   HostName foobar.baz.edu
   ProxyCommand ssh -ND 9999 %h
2
  • 1
    This is not really relevant to the question. -N and ProxyCommand are not the same thing.
    – kasperd
    Sep 26, 2018 at 23:10
  • 6
    Right, they are not, but this approach lets OP do what they say they want to do: set up one of the SSH connections in their ssh_config file to use the -N ssh flag, so they don't have to use -N every time they execute ssh host. Sep 27, 2018 at 13:41
4

I'm fairly sure you can't do that and like you I can't find a way of doing it in the manner that you want. If typing ssh -N host doesn't appeal then you could always try creating an alias if mosh supports it.

Time passes ... see below https://serverfault.com/a/1152274/9517

5
  • Yeah thanks, my plan was to use the ssh config together with the ssh workflow for Alfred (OS X). That would allow me to type ssh vps01 in Alfred and have it launch a terminal window for forwarding without the shell. Guess I'll have to solve it some other way then :) Sep 11, 2013 at 13:34
  • @DanielJohansson: I don't know anything about mosh but in bash you could alias it.
    – user9517
    Sep 11, 2013 at 13:41
  • 1
    This answer is almost 3 years old. Has anything changed in the meantime?
    – vog
    Aug 9, 2016 at 14:59
  • 1
    @vog yes it did, in 2021, with SessionType. See my answer below.
    – MestreLion
    Jan 26 at 13:40
  • 1
    @MestreLion Hehe, well, I know, because it was myself adding that feature to OpenSSH. ;-) See also: njh.eu/openssh
    – vog
    Feb 5 at 11:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .