How To Use openssh -o Flag
Unfortunately for me, I’m stuck using Matrix to communicate to people. The client I use to do this is iamb on a remote machine. On emacs, I’m able to get notifications for IRC messages with dbus and dunst. I wanted to get the same for notifications from my friends with iamb.
It’s entirely possible, I used this blog post: https://nikhilism.com/post/2023/remote-dbus-notifications/ to figure out how.
The blog explains how to setup your ssh config to forward your dbus socket.
Host remote-workstation
# IP address/hostname of the remote.
Hostname 192.168.34.11
# ... Any other settings you may have like User or IdentityFile.
# The crucial bits. It is confusing, but the remote socket comes first.
# Replace `/run/user/1000/bus` by the value you got from step 6.
RemoteForward /tmp/ssh_dbus.sock /run/user/1000/bus
The problem is, I’m using GNU Guix System, and I don’t exactly have an ssh config, instead, everything is managed by guix home. Of course, I could add this to guix home for this host, but then I have to reconfigure, why bother with that when ssh can do this with flags? Haven’t I seen -o used before?
So I popped open the ssh(1) manual and was greeted with this.
-o option
Can be used to give options in the format used in the configuration file. This is useful for specifying options for which there is no separate command-line flag. For full details of the options listed below, and their possible values, see ssh_config(5).
Well that is incredibly unhelpful. Let’s see if ssh_config(5) can help us,
"The file contains keyword-argument pairs, one per line. Lines starting with ‘#’ and empty lines are interpreted as comments. Arguments may optionally be enclosed in double quotes (") in order to represent arguments containing spaces. Configuration options may be separated by whitespace or optional whitespace and exactly one ‘=’; the latter format is useful to avoid the need to quote whitespace when specifying configuration options using the ssh, scp, and sftp -o option."
This has the answer, but I didn’t see it when I first read it.
The correct way to use it is this
ssh -o "RemoteFoward /tmp/ssh_dbus.sock /run/user/1000/bus" 127.0.0.1
You can also use = so you could write…
ssh -o TCPKeepALive=no 127.0.0.1
or
ssh -o "TCPKeepAlive no" 127.0.0.1
While I’m writing this blogpost long after I solved my problem, I did end up finding a somewhat helpful example of this in the ssh(1) manpage:
VERIFYING HOST KEYS
...
ssh -o "VerifyHostKeyDNS ask" host.example.com
...
Rather then finding that example, I figured it out by banging my head against the wall, and reading completely unrelated stack overflow answers until I guessed that smushing it together with quotes and spaces would work.
So, perhaps it is my fault for not reading the ssh and ssh_config manual more closely, and expecting to be spoonfed. All of the answers are there just not explicitly spelled out. Perhaps though, the format in which you pass options to the -o flag should be documented, in the -o section. Or at least an example should be directly there. Who knows?