ItecSoftware Logo

Exchange SSH keys and avoid logins and passwords

Written by Peter Gilg on - like this:
exchange ssh keys

If you’re working on remote systems, such as cloud instances or remote servers in a Linux environment, or as a system administrator or dba, changes are you’re often using ssh. Copying files between servers and workstations, creating database backups or using rsync to keep servers in sync are all tasks familiar to you.

I personally find it very annoying to always have to type in my login credentials. Not only is it less secure, but for my confortable nature being way too much work.

To avoid that, we can exchange ssh keys so that all the authentication is done utilizing those keys. We achieve that by following these two simple steps.

1. Generate a new ssh key

On the workstation, create a ssh key which we can share with the server.

$ ssh-keygen

2. Copy the generated ssh key to the target server(s)

Once we got our key, we copy it to the target server, so there is a reference to it.

$ cat ~/.ssh/ | ssh user@target_machine cat - ">>" ~/.ssh/authorized_keys

That’s all there is to exchange ssh keys. From now on, we can simply establish our ssh session providing our key and no login or password is necessary. Just ensure that you keep your key secure and safe from predators. Should it fall into the wrong hands, all bets are off and your servers are compromised like an open book.

Listed in Linux, Shell Scripting

Tags: key, key exchange, login, pasword prompt, ssh

Leave a Reply