Linux stuff I should remember but need to keep looking up

Inspired by Decryption’s blog post.

SSH Key Login

Passwords are so 2019. I’m copying the imporant bits from this article.

Generate a Key

If you don’t already have an ssh key on the local machine (usually located at ~/.ssh/, generate one with

ssh-keygen -t ed25519 -b 4096

Then there’s some permissions stuff to do:

  • For macOS / Linux, run the following shell command, replacing the path to your private key if necessary:chmod 400 ~/.ssh/id_ed25519
  • For Windows, run the following command in PowerShell to grant explicit read access to your username:icacls "privateKeyPath" /grant :R Then navigate to the private key file in Windows Explorer, right-click and select Properties. Select the Security tab > Advanced > Disable inheritance > Remove all inherited permissions from this object.

Install the key on the remote machine

From Linux or Mac OS: Run this command on your local machine

export USER_AT_HOST="your-user-name-on-host@hostname"
export PUBKEYPATH="$HOME/.ssh/"

ssh-copy-id -i "$PUBKEYPATH" "$USER_AT_HOST"

From Windows (Powershell): Run this command on your local machine


$pubKey=(Get-Content "$PUBKEYPATH" | Out-String); ssh "$USER_AT_HOST" "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '${pubKey}' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Here’s some more VS Code specific SSH stuff (tunnels, port forwarding etc)