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: ssh -G shows the settings SSH will really use for a host

Network and access
~/tips/tip-ssh-g-effective-config

ssh -G myserver | grep -E '^(hostname|user|port|identityfile) '

Prints the final SSH settings for a host after every Host and Match block is applied, without connecting.

My SSH config has grown into a pile of Host blocks, and when a login uses the wrong user or key I stop trusting my own eyes. ssh -G settles it.

The flag makes ssh evaluate your Host and Match blocks, print the resulting configuration and exit. It never opens a connection, so it is safe to run on any alias.

ssh -G myserver | grep -E '^(hostname|user|port|identityfile) '

The output uses lowercase keywords, one setting per line. You see the real hostname behind the alias, the user, the port and the identity files that apply. The patterns Host * and Host web-* are already merged in, so you no longer have to work out which block wins.

I like it most for the “why is it asking for a password” moment. One grep shows whether the block I meant to match actually matched, and I can fix the config instead of guessing.

One caveat: -G only reports what ssh would try. It says nothing about whether the server is reachable, whether the key is accepted or whether a firewall is in the way. For that, add -v to a normal login. Also remember that command-line options beat the config file, so ssh -G -p 2222 myserver shows a different port than the same command without -p.

Further reading: ssh(1) manual, ssh_config(5) manual

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