How do I copy files from one domain name to another using the shell?
If you have multiple domain names hosted with us, we assign each domain name a different Unix user ID to prevent cross-site contamination.
However, occasionally customers who use the command-line shell need to copy files between those domain names using rsync or other SSH tools.
While you can simply type the password on the shell command line, you can also use SSH keys to avoid that.
To do this, create a key on the “source” domain name you’ll be connecting from by typing ssh-keygen -t rsa and saving it without a password, like this:
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/ex/example.com/.ssh/id_rsa): Created directory '/home/ex/example.com/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/ex/example.com/.ssh/id_rsa. Your public key has been saved in /home/ex/example.com/.ssh/id_rsa.pub.
Then copy the contents of the new “id_rsa.pub” key to the “destination” server. An easy and safe method is to display the contents of the file on the source server by typing something like less ~/.ssh/id_rsa.pub, then selecting the displayed text and copying it to your clipboard.
What you copied should look something like this example:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0X5UPVf+m8a2+X0iSKoqiCKvWw3U5i9yod G/Q0xSg9fNHyRwGFXBdeI61N4fH1y6efafRjXsf7U4NeuyHQRG3MwHSiDUyDmukcuOmOZVUqS dBoxJRdHztetxtbrm0ye1YsYrw9MrFgSAtT8F example.com@web99
Now login to the shell of the “destination” domain name and add that public key (as a single line) to the file ~/.ssh/authorized_keys. You can create the directory and edit the file from the shell with these commands:
mkdir -p ~/.ssh editor ~/.ssh/authorized_keys
After doing this, you should be able to connect from the source domain name to the destination domain name without a password, using:
Commands that use SSH as the underlying protocol, such as “rsync” and “scp”, should also work, such as:
rsync -av directory firstname.lastname@example.org:~/html/ scp file email@example.com:~/html/