(This post is more of a note to self)
Recently, I had to set up an automatic backup of a certain database to be copied over to the backup server over SFTP. I had some problems with authentication when sending within the script, so I followed these simple steps to “automate” the authentication process. Client will have the user connecting to the server. On the client, we generate a key and we tell the server you should trust this key.
- Login as the user who will be sending the package
Generate public/private keys
ssh-keygen -t rsa
- This will generate a id_rsa.pub -file in ~/.ssh
Copy it to the server
scp ~/.ssh/id_rsa.pub user@server:~/.ssh/temp_rsa.pub
- Done on the client
This is what you need to do on the server (the target machine)
- Login as the user to which the client will be logging into
Add the client’s key to ~/.ssh/authorized_keys
cat ~/.ssh/temp_rsa.pub >> ~/.ssh/authorized_keys
Of course Your Mileage May Vary but that’s basically it!