Generating ssh keys
Generate a ssh key to connect without need for a password.
- You must be on the client that you want to automatically connect.
ssh-keygen- Add the key to the authorized keys on the server
ssh-copy-id -i {private key} {user}@{hostname}
- If you use the same key on multiple hosts, you can enable ssh agent forwarding when you connect to a host by using the
-Aoption of ssh
Multiple keys: a key per host
You can generate as many keys as you want, and set up ssh to use a different key for every host.
- Edit
~/.ssh/config - For every host enter the following:
# What you will write in the ssh command as hostname (ssh user@hostname). Can be multiple values separated by spaces to match multiple hosts or have aliases
Host {host}
# Where the connection will actually be made (actual address/name of the server). Can be %h if you want it to have the value specified in the command line (useful for using the same key on multiple machines)
Hostname {actual address}
# The identity used for this connection
IdentityFile {path to you ssh secret key}