31

I would like to use the -N flag in my ssh config file, but I'm not sure how to do this?

Is it possible?

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


Host foo
    HostName foo.bar.com
    User baz
    <how can I add -N flag here?>
4
  • Sounds like a case of the XY problem. What exactly do you want to do?
    – terdon
    Commented Dec 13, 2012 at 16:02
  • @terdon I am trying to pass the -N flag to ssh for a gitolite server my work has that appears to be slow during push/pull. I was told this will stop ssh from executing a shell on startup and loading the environment and stuff which is contributing to the lag I'm experiencing.
    – veilig
    Commented Dec 13, 2012 at 16:37
  • Why don't you just run ssh -N, why do you need to set this as a config parameter?
    – terdon
    Commented Dec 13, 2012 at 16:43
  • Answered here unix.stackexchange.com/a/417373/69080. Try RemoteCommand cat Commented May 24, 2018 at 13:53

4 Answers 4

7

Answered here https://unix.stackexchange.com/a/417373/69080. Starting in OpenSSH 7.6, there is an option called RemoteCommand. Try adding to your config file:

RemoteCommand cat

When using this, I also like to also include:

LogLevel DEBUG
2
  • 2
    Nice one. I added RemoteCommand echo "Tunneling through xxxxx machine. CTRL+C to terminate connection"; cat to get some feedback.
    – iamc
    Commented Nov 5, 2020 at 9:57
  • 1
    Since I originally wrote this, instead of cat, I now prefer sleep infinity if the remote machine supports it. Some old implementations of sleep might not support inifinity, so sleep 86400 is probably good enough. Another good option is tail -f. Problem with cat is if you send an EOF (ctrl+d) on the input, it will close the tunnel, which you may or may not want. Commented Nov 6, 2020 at 19:49
5

I know this question was asked for Linux but at least for macOS (Ventura 13), I can add SessionType none to any host I want and it works exactly as the flag -N. Hope this info is useful to someone :)

small edit: As it was pointed out in the comments above, I'm currently using openSSH version 9.0p1. Hope that's a little more general.

2
  • 1
    Big Linux distros use OpenSSH. Your solution works in OpenSSH. Commented Dec 27, 2022 at 19:14
  • 1
    For the record, SessionType was introduced in OpenSSH 8.7, released in 2021-08-20: "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."
    – MestreLion
    Commented Jan 24 at 16:27
2

Which OS? Do a man ssh_config and see if your ssh has such an option. On linux it this option is not available as a config parameter. As far as I know, I think the same is true with other openssh or similar clients in other platforms.

1
  • Ubuntu 12.04, I looked at the ssh_config man page but unless I overlooked it I didn't see it possible.
    – veilig
    Commented Dec 13, 2012 at 16:34
2

actually -N is not a parameter but just a flag like -l or else

if you don't want to have command ssh -N -l username HOSTNAME you can create alias ssh = "ssh -N" (on the host from where you want to ssh to your gitolite server.

another idea that came to my mind , the slowness of ssh can be because of DNS also, on connection server is trying to resolve hostname of machine which is trying to connect and if there are a wrong entry in DNS or no info available it will become slow on connection

kinds

You must log in to answer this question.

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