brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: RemoteCommand in ssh_config runs a command every time you connect

Network and access
~/tips/tip-ssh-remotecommand-requesttty

RemoteCommand tmux new -A -s main

Land in the same remote session or folder automatically when you open SSH.

On some servers the first step after logging in is always the same: attach to your tmux session. RemoteCommand puts that step in the ssh config, so ssh dev does it for you.

Host dev
    HostName dev.example.com
    RemoteCommand tmux new -A -s main
    RequestTTY yes

RemoteCommand is what you would otherwise type after the host name on the command line. RequestTTY yes matters here: when you give ssh a command, it normally does not allocate a terminal, and full screen programs like tmux or htop then refuse to start. It is the config version of ssh -t.

tmux new -A -s main attaches to the session called main, or creates it when it does not exist yet. Something like cd /srv/app && exec $SHELL -l works too if you just want to start in a certain folder.

The downside shows up when you want a plain connection to that host. scp, sftp and rsync go through the same Host block, and a forced command or terminal can get in their way. The man page lists -o RemoteCommand=none and -T for one-off overrides:

ssh -o RemoteCommand=none -T dev uptime

I’d keep a second alias like Host dev-plain without these two lines for file transfers, which is simpler than remembering the flags.

Further reading: ssh_config man page, ssh man page

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link