Skip to content

Instantly share code, notes, and snippets.

@royki
Last active November 29, 2020 19:32
Show Gist options
  • Save royki/7e5f83887e2367e1cd3b340830f3f6e6 to your computer and use it in GitHub Desktop.
Save royki/7e5f83887e2367e1cd3b340830f3f6e6 to your computer and use it in GitHub Desktop.
copy commad over ssh

To copy using scp and no password

  • create a folder of own user and become the owner of that folder by chown: folder_name

copy over ssh using scp

  • scp gitlabhq_stag.backup royki@gitlab127.0.0.1.net:/gitlab-data/dump

Copy a Local File to a Remote System with the scp Command

  • scp file.txt royki@10.10.0.2:/remote/directory
  • If SSH on the remote host is listening on a port other than the default 22 then you can specify the port using the -P argument:
    • scp -P 2322 file.txt royki@10.10.0.2:/remote/directory
  • copy a directory from a local to remote system use the -r option
    • scp -r /local/directory royki@10.10.0.2:/remote/directory
  • Copy a Remote File to a Local System using the scp Command
    • scp royki@10.10.0.2:/remote/file.txt /local/directory
  • Copy a File Between Two Remote Systems using the scp Command
    • scp user1@host1.com:/files/file.txt user2@host2.com:/files
  • To route the traffic through the machine on which the command is issued use the -3 option:
    • scp -3 user1@host1.com:/files/file.txt user2@host2.com:/files

scp Performance

By default scp uses the Triple-DES cipher to encrypt the data being sent. Using the Blowfish cipher has been shown to increase speed. This can be done by using option -c blowfish in the command line.

  • scp -c blowfish some_file your_username@remotehost.com:~
  • It is often suggested that the -C option for compression should also be used to increase speed. The effect of compression, however, will only significantly increase speed if your connection is very slow. Otherwise it may just be adding extra burden to the CPU. An example of using blowfish and compression:
    • scp -c blowfish -C local_file your_username@remotehost.com:~

SCP options:

  • –r Recursively copy entire directories. Note that this follows symbolic links encountered in the tree traversal.
  • -C Compression enable. Passes the -C flag to ssh to enable compression.
  • -l limit – Limits the used bandwidth, specified in Kbit/s.
  • -o ssh_option – Can be used to pass options to ssh in the format used in ssh_config.
  • -P port – Specifies the port to connect to on the remote host. Note that this option is written with a capital ‘P’.
  • -p Preserves modification times, access times, and modes from the original file.
  • -q Quiet mode: disables the progress meter as well as warning and diagnostic messages from ssh.
  • -v Verbose mode. Print debugging messages about progress. This is helpful in debugging connection, authentication, and configuration problems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment