Created
February 22, 2019 14:25
-
-
Save Sakib37/b811ae08646243e8e72508fda0e8dbca to your computer and use it in GitHub Desktop.
useful "scp" commands to trasfer files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy ssh key to a remove server | |
################################# | |
ssh-copy-id LOCAL_PATH_TO_THE_KEY USER_NAME@REMOTE_HOST:REMOTE_LOCATION | |
# ssh-copy-id may not be installed in the remote server. In that case, First create .ssh directory on remote server | |
ssh USER_NAME@REMOTE_HOST:REMOTE_LOCATION "umask 077; test -d .ssh || mkdir .ssh" | |
## cat local public key file and pipe over ssh to append the public key in the remote serve. Example- | |
cat ~/.ssh/id_rsa.pub | ssh user@remote_ip_or_hostname "cat >> .ssh/authorized_keys" | |
# Copy file to the remote system | |
################################# | |
# Basic scp command | |
# From host to remote | |
scp source_file_name dst_username@destination_host:destination_folder | |
# From remote to host | |
scp dst_username@destination_host:destination_file ~/my_local_file.txt | |
# or just download the file | |
scp [email protected]:/some/path/file.txt | |
# Transfer multiple files | |
# From host to remote | |
scp foo.txt bar.txt username@remotehost:/path/directory/ | |
# From remote to host | |
scp username@remotehost:/path/directory/\{foo.txt,bar.txt\} | |
# or just download | |
scp [email protected]:~/\{abc.log,cde.txt\} | |
# To copy recusively use '-r' parameter | |
scp -r ~/Downloads [email protected]:/root/Downloads | |
# Copy across two remote host | |
scp user1@remotehost1:/some/remote/dir/foobar.txt user2@remotehost2:/some/remote/dir/ | |
# For verbose output use the '-v' parameter | |
scp -v Label.pdf [email protected]:. | |
# Speed up file transfer by using '-C'(Capital) to compress | |
scp -vrC ~/Downloads [email protected]:/root/Downloads | |
# Limit bandwidth for transfer by using 'l' parameter | |
scp -vrC -l 400 ~/Downloads [email protected]:/root/Downloads # bandwidth 4 kibt/s | |
# Connect to different port number on remote host | |
scp -vC -P 2200 ~/test.txt [email protected]:/some/path/test.txt # remote port 2200 | |
# '-p' option (smallcase), would preserve modification times, access times, and modes from the original file. | |
scp -C -p ~/test.txt [email protected]:/some/path/test.txt | |
# To use specific key file use '-i' option | |
scp -vCq -i private_key.pem ~/test.txt [email protected]:/some/path/test.txt | |
# To use different ssh_config file specify the file using '-F' option | |
scp -vC -F /home/user/my_ssh_config ~/test.txt [email protected]:/some/path/test.txt | |
# Speed up the transfer by using different encryption(default AES). '-c' option to choose different cypher | |
scp -c blowfish -C ~/local_file.txt username@remotehost:/remote/path/file.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment