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
- ssh to the remote computer
- Type my password
- 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
)