rsync:rsync_files_securely_with_and_without_a_password
Differences
This shows you the differences between two versions of the page.
rsync:rsync_files_securely_with_and_without_a_password [2016/11/18 16:14] – created peter | rsync:rsync_files_securely_with_and_without_a_password [2019/12/04 18:54] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== RSync - Rsync Files Securely With and Without a Password ====== | ||
- | <code bash> | ||
- | rsync -avz -e ssh [Source File/ | ||
- | </ | ||
- | |||
- | To automate backups or avoid storing passwords within scripts, etc. | ||
- | |||
- | |||
- | ===== Generate private/ | ||
- | |||
- | <code bash> | ||
- | mkdir ~/ | ||
- | ssh-keygen -t rsa -b 2048 -f ~/ | ||
- | </ | ||
- | |||
- | ===== Place the public key in the authorized_keys file on the remote server ===== | ||
- | |||
- | <code bash> | ||
- | cat my-ssh-keys/ | ||
- | cooluser@remote.example.com' | ||
- | </ | ||
- | |||
- | |||
- | ===== Set permissions ===== | ||
- | |||
- | Make sure the .ssh folder and authorized keys have the proper permissions on the remote server: | ||
- | |||
- | <code bash> | ||
- | chmod 0700 ~/.ssh | ||
- | chmod 0644 ~/ | ||
- | </ | ||
- | |||
- | |||
- | ===== Log into the remote server ===== | ||
- | |||
- | <code bash> | ||
- | ssh -i my-ssh-keys/ | ||
- | </ | ||
- | |||
- | Keep in mind if you don’t have you use the " | ||
- | |||
- | |||
- | ===== Security restrict ===== | ||
- | |||
- | In order to provide a bit of security, we want to restrict this automation by source connection and authorized commands. | ||
- | |||
- | From: | ||
- | |||
- | < | ||
- | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCWPasgSOp0CxIvp6 | ||
- | kj0f0syDXLl55RAXNMkKz2K6FhYwbDMDIVWBemtKICHmaC5dtLBMSIT | ||
- | ozO4+CZvM2EdrCBALOnas93zpeMdpexkae3dItq7eTmSCd+AzVJdaRw | ||
- | lKXIrAgyzhlaHCEbfmbScPR6EEKxKasF9vd4ZaH1nYN8h7DZjmyzEGR | ||
- | </ | ||
- | |||
- | To: | ||
- | |||
- | |||
- | < | ||
- | from=" | ||
- | no-pty, | ||
- | no-X11-forwarding ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCWPasg | ||
- | SOp0CxIvp6kj0f0syDXLl55RAXNMkKz2K6FhYwbDMDIVWBemtKICHmaC5dtLBM | ||
- | SITozO4+CZvM2EdrCBALOnas93zpeMdpexkae3dItq7eTmSCd+AzVJdaRwlKX | ||
- | </ | ||
- | |||
- | |||
- | ===== Create a script ===== | ||
- | |||
- | We need to create the script to ensure only the rsync command is allowed for this user: | ||
- | |||
- | |||
- | < | ||
- | sudo vim / | ||
- | </ | ||
- | |||
- | <file bash / | ||
- | #!/bin/sh | ||
- | |||
- | set $SSH_ORIGINAL_COMMAND | ||
- | |||
- | case " | ||
- | | ||
- | ;; | ||
- | *) | ||
- | | ||
- | exit 1 | ||
- | ;; | ||
- | |||
- | esac | ||
- | |||
- | logger -t invalid-command -- " | ||
- | |||
- | exec " | ||
- | </ | ||
- | |||
- | |||
- | ===== Setting the proper permissions ===== | ||
- | |||
- | <code bash> | ||
- | sudo chmod +x / | ||
- | sudo chown root:root .ssh/ | ||
- | sudo chmod 0644 .ssh/ | ||
- | </ | ||
- | |||
- | |||
- | ===== Test it ===== | ||
- | |||
- | <code bash> | ||
- | touch testfile.txt | ||
- | |||
- | rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/ | ||
- | </ |
rsync/rsync_files_securely_with_and_without_a_password.1479485641.txt.gz · Last modified: 2020/07/15 09:30 (external edit)