I need to be able to setup a ssh
key system without interaction. I don't care if packages need to be installed or passwords in clear text.
How can I make a system that sets up a ssh
key system, allowing machine A to ssh
into the machine B and vice versa using ssh keys, without interaction?
Here's the plain code (copying and pasting WILL NOT WORK!!! Change things like
my-username
andmy-ip
). Run on both hosts:Replace
my_host_2
withmy_host_1
on machine 2.Explanation:
The first line,
#!/bin/bash
is called a shebang. Look here for more information.The second line installs
sshpass
without interaction.The third line uses
ssh-keygen
to create a key.-q
means quiet; it dosen't ask as much.-N ""
means no password and-f
means to save it in the default location.The last line copies the actual key using
ssh-copy-id
andsshpass
. You cannotecho
the password throughstdin
, so we usesshpass
which is the closest equivalent.-p
is the password to use. The argument tossh-copy-id
is the username and host to copy the key to.