Setting Up SSH Key for Passwordless File Transfer - Carleton-SRCL/SPOT GitHub Wiki

Setting Up SSH Key for Passwordless File Transfer

This guide will help you set up SSH keys on three Linux systems to enable passwordless file transfer between them. We'll assume that you already have SSH installed on all systems. If not, please install OpenSSH with sudo apt-get install openssh-server. You only need to follow this guide if you are setting up the entire SPOT software suite from scratch (include the onboard computers).

Generate SSH Key

Follow these steps on all three of the platform computers:

  1. Open Terminal
  2. Enter ssh-keygen -t rsa -b 4096. This command generates a new 4096-bit RSA key pair.
  3. When prompted, press Enter to accept the default file location.
  4. You'll be asked to enter a passphrase. For a passwordless setup, just press Enter to leave this blank. This will create two files in your .ssh directory: id_rsa and id_rsa.pub. The former is your private key and should never be shared, while the latter is your public key.

Copy SSH Keys

To allow the systems to authenticate each other, you need to copy the public key (id_rsa.pub) from each machine to the others. Do this for all pairs of machines (RED-BLACK, RED-BLUE, BLACK-BLUE).

Use the ssh-copy-id command as shown below. Replace username with your user name and remote_host with the host name or IP address of the other machine. So, for example if you are setting up the RED-BLACK key you would run the following command on RED:

ssh-copy-id [email protected]

You'll need to enter the password for the remote machine. After this, you won't need to enter it again thanks to the SSH key.

Test Connection

Try connecting from one machine to another with ssh username@remote_host. You shouldn't need to enter a password.

SCP for File Transfer

You can use the scp command to transfer files between machines. Here's a basic example:

scp /path/to/local/file username@remote_host:/path/to/remote/directory

If you've followed the steps correctly, this won't ask for a password, and you should see the file on the other computer.

Troubleshooting

If you're having trouble:

  • Ensure that all three machines have each other's public keys.
  • Check that the .ssh directory and its contents have the correct permissions (chmod 700 ~/.ssh; chmod 600 ~/.ssh/*).
  • Look for error messages in the SSH log with sudo journalctl -f -u ssh.