tips
163 tips Network and access
One command, setting or habit at a time about Network and access: what it does, the line to copy and a caveat or two.
SSH 58
-
Copy a file from one server to another with scp, routed through the machine you type on
scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ -
Sets an environment variable in the remote session straight from your ssh config.
SetEnv PROJECT_ENV=staging -
Restricts SSH port forwarding to a short list of host:port destinations for a user.
Match User tunnel -
Lets ssh replace a leftover Unix socket file when forwarding to a socket again.
ssh -o StreamLocalBindUnlink=yes -L /tmp/app.sock:/run/app.sock host -
Runs a local command right after ssh connects, with tokens such as the remote hostname.
LocalCommand echo "%r@%h %n" >>> ~/.ssh/connections.log -
Give a backup or deploy key exactly one thing it may do on the server.
restrict,command="/usr/local/bin/backup.sh" ssh-ed25519 AAAAC3Nza... backup@example -
Know how OpenSSH 9.8 and later block noisy addresses by themselves, and how to tune it.
PerSourcePenalties authfail:30s max:30m -
Land in the same remote session or folder automatically when you open SSH.
RemoteCommand tmux new -A -s main -
Fix scp errors on routers and old servers that have no SFTP subsystem.
scp -O backup.tar user@old-router:/tmp/ -
Use a direct address at home and a jump host elsewhere, with one host name.
Match host nas localnetwork 192.0.2.0/24 -
Make ssh add your domain to short names and then apply the matching config block.
CanonicalizeHostname yes -
Sign and verify files with the SSH key you already have, without setting up GPG.
ssh-keygen -Y sign -f ~/.ssh/id_ed25519 -n file release.tar.gz -
Force IPv4 for SSH when a host's IPv6 address resolves but does not work.
ssh -4 [email protected] -
Run a second sshd in the foreground on another port and watch why logins fail.
sudo /usr/sbin/sshd -d -p 2222 -f /etc/ssh/sshd_config.new -
Give someone file upload access in one folder without a shell on the server.
ForceCommand internal-sftp -
Point ssh at a different agent socket per host, or switch the agent off entirely.
Host github.com -
Log out forgotten shells and stale tunnels after a set time of inactivity.
ChannelTimeout session=30m direct-tcpip=1h -
Rename the label on an existing key so you can tell keys apart later.
ssh-keygen -c -C "work laptop 2026" -f ~/.ssh/id_ed25519 -
Store a separate host key per machine when several share one address on different ports.
Host vm1 -
Sign user keys with a CA so servers stop needing every public key in authorized_keys.
ssh-keygen -s user_ca -I alice-laptop -n alice -V +52w id_ed25519.pub -
Regenerate missing host keys so cloned machines stop sharing one server identity.
sudo ssh-keygen -A -
Make a service on your laptop reachable from a remote server through the SSH connection.
ssh -R 8080:localhost:3000 [email protected] -
Find out in one command which account your key logs in as on a Git host.
ssh -T [email protected] -
Keep the SSH server off the public interface and listening only where you want it.
ListenAddress 192.0.2.10 -
Require two login steps, so a stolen key or a guessed password alone is not enough.
AuthenticationMethods publickey,password -
Stop users from using your SSH server as a tunnel or proxy into your network.
DisableForwarding yes -
Use different SSH server rules for logins from your own network and from outside.
Match Address 192.0.2.0/24 -
Switch a block of ssh_config settings on per command with a tag name.
Match tagged tunnel -
Script uploads and downloads with sftp and stop at the first failed command.
cd /var/www/upload -
See which ciphers, key types and key exchanges your own ssh build can use.
ssh -Q cipher -
Give a temporary key a built-in end date so nobody has to remember to remove it.
expiry-time="20270131" ssh-ed25519 AAAAC3Nza... guest@example -
Correct the permissions sshd checks before it trusts your authorized_keys file.
chmod 700 ~/.ssh -
Starts a local SOCKS proxy that sends your browser traffic through an SSH server.
ssh -D 127.0.0.1:1080 [email protected] -
Reads extra ssh config files from a folder, so each group of hosts gets its own file.
Include config.d/* -
Makes sshd check silent clients and disconnect them after a number of missed replies.
ClientAliveInterval 60 -
Opens ssh's own command line in a live session so you can add or cancel port forwards.
[email protected]:~$ ~C -
Searches known_hosts for one host name and prints the entries it finds.
ssh-keygen -F example.com -
Loads an SSH key into the agent for a limited time only.
ssh-add -t 1h ~/.ssh/id_ed25519 -
Stops ssh from asking for passwords or confirmations, so a script fails fast instead of hanging.
ssh -o BatchMode=yes -o ConnectTimeout=5 [email protected] uptime -
Turns the host names in known_hosts into hashes so the file no longer lists your servers.
ssh-keygen -H -f ~/.ssh/known_hosts -
Raises the number of key derivation rounds so a stolen SSH key file is harder to brute-force.
ssh-keygen -t ed25519 -a 100 -C "laptop" -
Lowers how many authentication attempts sshd allows per connection, default 6.
MaxAuthTries 3 -
Caps unauthenticated SSH connections and shortens the login window to blunt connection floods.
MaxStartups 5:50:20 -
Stops ssh from offering every key in the agent and sends only the identity file you named.
IdentitiesOnly yes -
Lets you log in to your Mac over SSH or SFTP from another computer.
System Settings > General > Sharing > Remote Login -
Closes a hanging SSH session from your own keyboard without closing the terminal.
Enter ~ . -
Prints the public key that belongs to a private key, so you can restore or match it.
ssh-keygen -y -f ~/.ssh/id_ed25519 -
Makes the SSH client check the server and drop a dead connection after about 45 seconds.
ServerAliveInterval 15 -
Limits SSH logins to a short list of user names, optionally from specific addresses.
AllowUsers alice [email protected]/24 -
Checks an SSH server's key exchange, ciphers and keys, and lists what to switch off.
pip3 install ssh-audit -
Adds, changes or removes the passphrase on an existing SSH private key.
ssh-keygen -p -f ~/.ssh/id_ed25519 -
Mounts a directory from another machine on a local folder, using nothing more than an SSH login.
sshfs user@server:/srv/data ~/remote -
Shows the fingerprints of all keys held by the SSH agent, so you know what can log in for you.
ssh-add -l -
Opens a local port forward through SSH in the background, with a clean way to close it.
ssh -f -N -o ExitOnForwardFailure=yes -M -S ~/.ssh/fwd.sock -L 8080:localhost:80 user@server -
Downloads the public host keys of a server, so you can inspect their fingerprints before trusting it.
ssh-keyscan -t ed25519 example.com | ssh-keygen -lf - -
Prints the final SSH settings for a host after every Host and Match block is applied, without connecting.
ssh -G myserver | grep -E '^(hostname|user|port|identityfile) ' -
Connects to a server through a jump host in one step, without a manual hop.
ssh -J user@jumphost user@internal-server -
Clears the old host key so SSH stops warning about a changed fingerprint after a reinstall.
ssh-keygen -R nas.local
Tailscale commands 42
-
Asks Tailscale which exit node it recommends for this device, without switching to it.
tailscale exit-node suggest -
Prints a device's current Tailscale settings, or the flags that would recreate them.
tailscale get -
Sends one DNS lookup through the resolver Tailscale runs on your machine, so you see what MagicDNS answers.
tailscale dns query nas -
See your tailnet lock key and the trusted signing keys from one device.
tailscale lock status -
Filter your device list with jq, for example to list every offline machine.
tailscale status --json | jq -r '.Peer[] | select(.Online == false) | .HostName' -
Point the regular Tailscale client at your own coordination server instead of Tailscale's.
sudo tailscale login --login-server=https://headscale.example.com -
Serve different local apps under different URL paths on one Tailscale HTTPS name.
tailscale serve --bg 8080 -
Change one Tailscale setting without restating every other flag you used before.
sudo tailscale set --update-check=false -
Let your shell complete Tailscale subcommands and flags instead of checking the help.
tailscale completion zsh > "${fpath[1]}/_tailscale" -
Keep original source addresses visible in logs behind a Linux subnet router.
sudo tailscale set --snat-subnet-routes=false -
Pass a Tailscale auth key from a protected file instead of typing it on the command line.
sudo tailscale up --auth-key=file:/root/ts-authkey -
Check the logged-in user and machine name before you change tailnet settings.
tailscale whoami -
Pick the right command to disconnect, so you do not have to re-authenticate by accident.
sudo tailscale down -
Use your own well-connected node as a relay when devices cannot connect directly.
sudo tailscale set --relay-server-port=40000 -
Run Tailscale in containers without a tun device and reach the tailnet through a proxy.
tailscaled --tun=userspace-networking --socks5-server=localhost:1055 --outbound-http-proxy-listen=localhost:1055 & -
Scan the login link from the terminal instead of copying a long URL by hand.
sudo tailscale up --qr -
Opens a raw connection to a port on a tailnet device from the command line.
tailscale nc my-server 8080 -
Blocks all incoming connections from your tailnet on one device.
tailscale set --shields-up -
Makes one device ignore the DNS settings that the Tailscale admin console sends.
tailscale set --accept-dns=false -
Shares a folder over your tailnet as WebDAV, with access decided by your Tailscale policy file.
tailscale drive share docs /srv/docs -
Makes a Tailscale device install new client releases on its own, without you checking the admin console.
sudo tailscale set --auto-update -
Opens a device's Tailscale settings in your browser from anywhere on your tailnet, without SSH.
sudo tailscale set --webclient -
Switches the device to another logged-in Tailscale account or tailnet without logging out.
tailscale switch --list -
Gives one Linux user the right to operate tailscaled, so routine commands need no sudo.
sudo tailscale set --operator=$USER -
Marks your Tailscale client logs with an identifier that you can hand to support.
tailscale bugreport -
Prints or writes the Tailscale client's usage metrics so a monitoring system such as Prometheus can read them.
tailscale metrics print -
Changes the name a device uses on your tailnet, without rerunning tailscale up or the full settings.
sudo tailscale set --hostname=nas -
Pauses a script or service start until the Tailscale interface and its addresses are available.
tailscale wait && /path/to/service -
Prints the Tailscale IPv4 address of this device, or of another device when you give its name.
tailscale ip -4 -
Shows whether your connection to another Tailscale device is direct or goes through a relay, and how fast it is.
tailscale ping my-nas -
Sends a file straight from your computer to your phone over Tailscale, no cloud in between.
tailscale file cp ./my-file.txt my-phone: -
When a site will not load and you run AdGuard Home or Pi-hole, the first question is whether the block comes from your resolver or from the internet. One command,…
dig +short example.com @192.168.1.3 -
Tells you if a connection on your Tailscale network is direct or goes through a relay.
tailscale ping my-server -
Lists the exit nodes available to you by country and suggests a recommended one.
tailscale exit-node list --filter=Netherlands -
Starts a Tailscale node that keeps no state on disk and is removed from the tailnet when done.
tailscaled --state=mem: -
Prints the local DNS forwarder and MagicDNS configuration so you can see why a device name fails.
tailscale dns status -
Changes the DNS servers of a network connection from the terminal, and resets them.
networksetup -listallnetworkservices -
Looks up the machine and user behind a Tailscale IP address, for example from a log line.
tailscale whois 100.101.102.103 -
Reports your network's UDP, NAT and relay conditions to explain why Tailscale connections go through a relay.
tailscale netcheck -
Shows only the Tailscale peers you are currently exchanging traffic with, including direct or relayed.
tailscale status --active -
Lists what a machine shares over Tailscale and wipes all Serve settings in one command.
tailscale serve reset -
Shares a local web app with your tailnet over HTTPS and keeps it running after a reboot.
tailscale serve --bg localhost:3000
DNS and Pi-hole 24
-
Controls for how many days Pi-hole keeps queries in its long-term database.
sudo pihole-FTL --config database.maxDBdays 30 -
Clears the Pi-hole DNS cache and reloads it, without restarting the whole service.
pihole reloaddns -
Removes one name, or a whole zone, from the Unbound cache so it is looked up again.
unbound-control flush www.example.com -
Resolve your local or company domain with its own DNS server while the rest goes upstream.
https://dns.quad9.net/dns-query -
Answer repeat lookups instantly while AdGuard Home refreshes the record in the background.
dns: -
Pick between load balancing, parallel and fastest address when you have several upstreams.
dns: -
Set Pi-hole's own host records from the command line instead of clicking through the UI.
sudo pihole-FTL --config dns.hosts '[ "192.0.2.20 nas.home.example", "192.0.2.30 printer.home.example" ]' -
Make a domain resolve to a local address for everyone on your network.
rewrites: -
Download and apply new or changed blocklists now instead of waiting for the weekly run.
pihole -g -
Watch what a device asks your DNS server in real time to find what gets blocked.
pihole tail -
Resets the DNS settings of one network interface back to its defaults.
resolvectl dns eth0 192.168.1.53 -
Syntax-checks the dnsmasq configuration and exits without starting the server.
dnsmasq --test -
Explains the answer types AdGuard Home can send for blocked domains and which one to choose.
dig @192.168.1.2 doubleclick.net -
Stops AdGuard Home from silently dropping DNS queries when many home devices ask at once.
dns: -
Prints cache hits, misses and DNSSEC verdicts from systemd-resolved so you can judge the cache.
resolvectl statistics -
Gives a custom AdGuard Home rule top priority, or limits it to specific devices on your network.
||example.org^$important -
Stops Nginx Proxy Manager from adding its own DNS resolver, so lookups use hosts and resolv.conf.
environment: -
Pauses Pi-hole blocking for five minutes, then turns it back on by itself.
pihole disable 5m -
Shows which Pi-hole list blocks a domain, so you can allow it.
pihole -q example.com -
Checks whether your DNS filter tells Firefox not to switch on its own encrypted DNS.
dig use-application-dns.net -
Lists the names Windows has cached, including entries from the hosts file.
ipconfig /displaydns -
Shows a live stream of the DNS lookups made on this machine.
resolvectl monitor -
Looks up a name and checks whether its DNSSEC signatures validate.
delv example.org -
Follows a DNS lookup from the root servers down to the authoritative answer, step by step.
dig +trace example.nl
Tailscale access and policy 15
-
Signs a new node's key from a signing node so it is accepted when Tailnet Lock is on.
tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 -
Allow only the protocols and ports a service needs instead of the whole device.
"grants": [ -
Let people reach their own devices without seeing anyone else's on a shared tailnet.
"grants": [ -
Name subnet addresses in your policy so rules say what they protect.
"hosts": { -
Give access to a named group once instead of listing email addresses in every rule.
"groups": { -
Gives a server a tag instead of your user account, so ACLs and key expiry treat it as a server.
sudo tailscale up --advertise-tags=tag:server --force-reauth -
Makes a device refuse incoming Tailscale connections while it can still reach others.
tailscale set --shields-up -
Keeps traffic flowing when the router with the more specific subnet route goes offline.
sudo tailscale set --advertise-routes=10.0.0.0/16,10.0.0.0/24 -
Lets chosen users route internet traffic through an exit node when your access rules are customised.
"acls": [ -
Sends DNS queries for one domain to a VPN's DNS server and leaves the rest alone.
resolvectl dns wg0 10.0.0.1 -
Approves advertised subnet routes and exit nodes automatically for the users or tags you name.
"autoApprovers": { -
Adds checks to the policy file that reject any change breaking an access rule you wrote down.
"tests": [ -
Makes Tailscale SSH ask for a fresh identity check before a login, with a period you choose.
"ssh": [ -
Lets you log in over SSH to a machine using your tailnet identity instead of key files.
tailscale set --ssh -
Makes Tailscale addresses count as local when Sonarr or Radarr skips the login for local addresses.
SONARR__AUTH__TRUSTCGNATIPADDRESSES=true
Network and DNS 11
-
Generates a random preshared key that adds a symmetric layer on top of a WireGuard peer's key pair.
wg genpsk > peer1.psk -
Tells wg-quick to bring the tunnel up without creating any routes, so you add your own.
Table = off -
Start a WireGuard interface automatically at boot with the unit that ships with wg-quick.
sudo systemctl enable --now wg-quick@wg0 -
Add or change a WireGuard peer without restarting the interface and cutting everyone off.
sudo systemctl reload wg-quick@wg0 -
Understand why traffic goes missing when a WireGuard peer's AllowedIPs list is too narrow.
AllowedIPs = 198.51.100.2/32, 192.0.2.0/24 -
Check when each WireGuard peer last completed a handshake to see if the tunnel works.
sudo wg show wg0 -
Stop a WireGuard tunnel from going deaf when the router forgets the UDP mapping.
PersistentKeepalive = 25 -
Create a WireGuard key pair without leaving the private key readable for other users.
umask 077 -
Tells systemd-resolved to skip DNSSEC validation for one domain on one link.
sudo resolvectl nta eth0 example.com -
Makes curl send a request for a hostname to an IP address you choose, ignoring DNS.
curl -I --resolve example.com:443:203.0.113.10 https://example.com/ -
Tests whether a TCP port accepts connections, without sending any data.
nc -zv example.com 443
Windows 4
-
Point a Windows network adapter at your own DNS server from PowerShell and undo it later.
Get-DnsClientServerAddress -AddressFamily IPv4 -
Empties the DNS cache on the Windows PC so names are looked up again.
ipconfig /flushdns -
Lists connections and listening ports in numeric form with the owning process ID, then tasklist names it.
netstat -ano | findstr :8080 -
Tests from PowerShell whether a remote TCP port accepts connections, and shows the ping result as well.
Test-NetConnection -ComputerName example.com -Port 443
Mac terminal 2
-
Resolve a home or lab domain with a specific server while everything else stays unchanged.
sudo mkdir -p /etc/resolver -
Measures your download and upload speed and the lag under load, without opening a browser.
networkQuality
Settings and access 2
-
Stop a headless server from losing its Tailscale connection when its node key expires.
sudo tailscale up --force-reauth -
Switches the hotspot to a mode that older devices can join, at some cost in speed and security.
Access and security 1
-
Fetches a Let's Encrypt certificate for your machine's tailnet name, so a service can use HTTPS.
sudo tailscale cert machine.your-tailnet.ts.net
Proxying 1
-
Starts a Caddy reverse proxy from the command line, with no config file.
caddy reverse-proxy --from :2016 --to :9000
Query options 1
-
Sends a query with the checking-disabled bit to see if DNSSEC validation causes a failure.
dig example.com +cd
WP-CLI 1
-
Gives a remote WordPress site a short name so wp commands run over ssh as wp @prod.
@prod:
systemd 1
-
Ends a hanging login session and every process that belongs to it.
loginctl list-sessions
Nothing in this filter yet.