The objective of this tutorial is to generate a SSH Key in order to connect to your server without set your password each time.
Prerequisites
- SSH installed (ex: OpenSSH, OpenBSD Secure Shell server)
Generating new SSH Key
- Execute this command below, substuting in your email address
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- Add the ssh key into ssh-agent
ssh-add ~/.ssh/id_rsa
You can see more in this tuto
Useful commands:
a. Get list of key:
ssh-add -L
b. Remove a key
ssh-add -D ~/.ssh/id_rsa
c. Copy the key into the clipboard
pbcopy < id_rsa_git_evs.pub
If you don’t have pbcopy, you can install it easily. Here an example for ArchLinux 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/jluccisano/.ssh chmod 644 /var/services/homes/jluccisano/.ssh/authorized_keys chmod 755 /var/services/homes/jluccisano
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 luccihermes.synology.me
User jluccisano
Port 87
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa_syno
ssh syno