0

I have two machines with the same folder structure. One is my personal computer, the other is a remote computer. Sometimes I want a program to run on the remote computer. At the moment I always need to

  1. ssh to the remote computer
  2. Type my password
  3. copy the folder manually using rsync

Even if I would write a script for rsync (like the one shown below) I would still need to enter my password every time or hard code it inside the bash script (which would be stupid).

#!/bin/bash/
pathToSync="/path/to/my/Folder/"
rsync -r -l -p --progress "$pathToSync"/ myUsername@nameOfRemoteComputer:"$pathToSync"

Has someone an idea of how to solve this problem more efficiently? Such that in the end I only need to write

sync myFolder nameOfRemoteComputer

The question has been answered.
As Addition to the correct answer given below. Here are the the bash commands to make ssh and rsync work without having to enter passwords. On the client computer type:

mkdir ~/.ssh # Maybe this folder already exists chmod 700 ~/.ssh cd ~/.ssh ssh-keygen -t rsa # This creates a public key cp authorized_keys authorized_keys_Backup # This backups old / existing keys cat id_rsa.pub >>~/.ssh/authorized_keys ssh-copy-id nameOfRemoteComputer

Done! (-> Check if ssh works without password now) (I have the same username on client and remote computer otherwise it would be ssh-copy-id myRemoteUsername@nameOfRemoteComputer)

3

SCP

Since you have ssh access you can just use command scp to do your work.

In terminal enter:

scp -r /path/to/my/folder myUsername@nameOfRemoteComputer:/path/to/my/folder

If you also use the same username on both computers you can even ommit myUsername@ and just enter:

scp -r /path/to/my/folder nameOfRemoteComputer:/path/to/my/folder

The name of the remote copumter can be an IP, a domain name or a name assigned at /etc/hosts.

Avoid Entering Password for SSH Connection

You could setup an SSH Key Pair between your server and your local machine.

I would suggest you use Passwords and Keyes app. It should come pre-installed on Ubuntu.

enter image description here

New Key Pair

Press the green + and create a new Secure Shell Key. Follow the dialog boxes to create a new key pair.

Here you can find terminal commands to generate the key pair id_rsa and id_rsa.pub, you will need to get a copy of id_rsa.pub to your server to make the key pair work.

Add the contents of id_rsa.pub to the file ~/.ssh/authorized_keys at your server in a new line. You could use command: cat id_rsa.pub >>~/.ssh/authorized_keys after login in through ssh.

If you set a passphrase to the private key you will have to enter the passphrase to ulock it. Assign no passphrase for ease of use.

  • But also in that case I would have to enter my password manually right? – mcExchange Jan 19 '16 at 14:15
  • You would need to use your password. You can set up an ssh-key to your remote server to avoid having to enter a password every-time. It is generally stronger than using a password you can remember and it will also make it so that you don't have to enter a password anymore. Are both of your machines using Ubuntu? – Torrien Jan 19 '16 at 14:17
  • Yes. They both run Ubuntu – mcExchange Jan 19 '16 at 14:19
  • Thanks, that worked :). I will add the commands I had to execute in my question above... – mcExchange Jan 19 '16 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.