Skip to content

Write the SSH block

$ grim server:dev:ssh-config dev1

VS Code Remote-SSH picks its targets from ~/.ssh/config, and nobody wants to type dev@203.0.113.10 every morning. Once a box exists, grim server:dev:ssh-config prints the block that gives it a short name. Paste it once per machine.

Usage

$ grim server:dev:ssh-config dev1             # by alias
$ grim server:dev:ssh-config 203.0.113.10     # the address works as well

Run it from anywhere. The argument is the address or alias of a server in your ~/.grim/servers.json, which means a server you set up from this machine.

Arguments and options

Print a ~/.ssh/config block for connecting to a dev VPS

Usage

grim server:dev:ssh-config <host>

Arguments

Argument Description
host Dev server host or alias (required)

What it actually does

  1. Looks the server up in ~/.grim/servers.json. It does not connect to anything.
  2. Prints a Host block. The name is the alias with -dev added, so dev1 becomes dev1-dev. The block sets HostName to the server's address, User dev, StrictHostKeyChecking accept-new, and a keep-alive every 30 seconds that gives up after three missed replies.
  3. Prints the two commands that use it: ssh dev1-dev, and code --remote ssh-remote+dev1-dev /home/dev/projects/<project>.

Nothing is written to ~/.ssh/config. The output starts with a comment line and ends with the two commands, so copy the block itself, from Host to ServerAliveCountMax.

Pitfalls

The block names no key

SSH offers your default keys. When the key you gave to grim server:dev:keys lives somewhere else, add IdentityFile ~/.ssh/<key> to the block by hand.

A colleague cannot run it

Unknown host "dev1". means the server is not in that person's servers.json, and it will not be unless they set the box up themselves. Run the command for them and send the block. It holds an address and a user name, nothing secret.

After it finishes

With the block pasted and a key on the box, the connection is one command.

$ ssh dev1-dev
$ code --remote ssh-remote+dev1-dev /home/dev/projects/shop

The project path and the rest of what a developer needs are on the card that grim server:dev:info prints.

Recipes that use it

Curses it can raise

kex_exchange_identification: Connection closed by remote host

sshd MaxStartups drops connections when a parallel sync opens too many at once.