Legacy post. This article was written between 2016 and 2018. Software versions, commands and services mentioned here may be outdated. Check the official documentation before running anything.
The goal of this tutorial is to generate an SSH key so you can connect to your server without typing your password each time.
Prerequisites
- SSH installed (for example: OpenSSH, OpenBSD Secure Shell server)
Generating new SSH Key
- Run the command below, replacing the email address with yours
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" - Add the SSH key to ssh-agent
ssh-add ~/.ssh/id_rsa
You can find more in this tutorial
Useful commands:
a. Get the list of keys:
ssh-add -L
b. Remove a single key (ssh-add -D removes all identities, so use -d for one key)
ssh-add -d ~/.ssh/id_rsa
c. Copy the key to the clipboard
pbcopy < id_rsa_git_evs.pub
If you don’t have pbcopy, you can install it easily. Here is an example for Arch Linux users.
Sending SSH key to a server
https://www.skyminds.net/se-connecter-depuis-un-serveur-vers-un-nas-synology-avec-des-cles-ssh-sans-mot-de-passe/
sudo vim /etc/ssh/sshd_config
Protocol 2 LoginGraceTime 2m RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys
chmod 700 /var/services/homes/
sudo synoservicectl –reload sshd
ssh-copy-id -i ~/.ssh/id_rsa.pub -p X username@address
Create Alias
cd ~/.ssh/
touch config
subl -a config
Host syno
Hostname <your-host.example.com>
User <user>
Port 87
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa_syno
ssh syno