Skip to content

Instantly share code, notes, and snippets.

@alex-salnikov
Last active March 10, 2022 11:14
Show Gist options
  • Save alex-salnikov/5b7fcd702a5c2e3b5979c900cc64b9be to your computer and use it in GitHub Desktop.
Save alex-salnikov/5b7fcd702a5c2e3b5979c900cc64b9be to your computer and use it in GitHub Desktop.
  1. on local machine - create ssh key-pair mykeyfile, mykeyfile.pub
$ ssh-keygen -q -N '' -b 4096 -f ~/.ssh/mykeyfile
  1. on local machine - display contents of public key (so that later you can copy/paste them into authorized_keys)
$ cat mykeyfile.pub
  1. on remote machine - create file ~/.ssh/authorized_keys (if not already exists), add the contents of public key as a new line into that file
$ nano ~/.ssh/authorized_keys
  1. on local machine - add configuration for remote-machine to local ssh-config (you can use VScode for that)
$ nano ~/.ssh/config
Host myremote                       <- alias
  HostName my-remote-machine.lan    <- hostname or ip
  User myremoteuser                 <- user-name on remote machine
  Port 22                           <- (optional) ssh port of remote-machine, if not default, for example: 2222
  IdentityFile ~/.ssh/mykeyfile     <- path to private (!!) key, not public
  1. on local machine - test ssh-connection to remote machine
$ ssh -Tvvv myremote
  1. on local machine - connect to remote
$ ssh myremote
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment