Skip to content

Instantly share code, notes, and snippets.

@LuczynskiDar
Last active April 3, 2020 14:25
Show Gist options
  • Save LuczynskiDar/9375a22d392a8923be4f666e1742efe2 to your computer and use it in GitHub Desktop.
Save LuczynskiDar/9375a22d392a8923be4f666e1742efe2 to your computer and use it in GitHub Desktop.
ssh-commands

remove via ssh

ssh hostname "rm -f z100.foo z200.foo" ssh [email protected] -p22 "rm -rf /home/amzad/test.php"

mkdir via ssh

ssh server1 "cd dir1 && tar -cf - ." | ssh server2 "( mkdir -p dir2; cd dir2 && tar -xf - )"

to overwrite

scp -prq server1:dir1/* server2:dir2/

Basic syntax of SCP

scp source_file_name username@destination_host:destination_folder

Provide the detail information of SCP process using -v parameter

scp -v Label.pdf [email protected]:.

Provide modification times, access times, and modes from original files

scp -p Label.pdf [email protected]:.

Compress files on go Make file transfer faster using "-C" parameter, pack during transfer

scp -Cpv messages.log [email protected]:.

Select another cipher to encrypt files, SCP using “AES-128” to encrypt files, use “-c”

scp -c 3des Label.pdf [email protected]:.

Specify specific port to use with SCP, Usually SCP is using port 22 as a default port. But for security reason, you may change the port into 2249.

scp -P 2249 Label.pdf [email protected]:.

Copy files inside directory recursively

scp -r documents [email protected]:.

Copy files using SCP through Proxy

Proxy server is usually used in office environment. Natively, SCP is not proxy configured. When your environment using proxy, you have to “tell” SCP to communicate with the proxy. Here’s the scenario. The proxy address is 10.0.96.6 and the proxy port is 8080. The proxy also implemented user authentication. First, you need to create “~/.ssh/config” file. Second you put this command inside it.

ProxyCommand /usr/bin/corkscrew 10.0.96.6 8080 %h %p /.ssh/proxyauth Then you need to create file “/.ssh/proxyauth” which contain. lease notice that corkscrew is might not installed yet on your system. myusername:mypassword$ apt-get install corkscrew

Select different ssh_config file

For mobile user who often switch between company network and public network, it will be suffer to always change settings in SCP. It is better if we can put a different ssh_config file to match our needs. By default “ssh_config” file per user will be placed in “~/.ssh/config“. Creating a specific “ssh_config” file with proxy compatible, will make you easier to switch between networks. When you are on company network, you can use “-F” parameter. When you are on public network, you can skip “-F” parameter

scp -F /home/pungki/proxy_ssh_config Label.pdf

scp -rq katalog/* label:c:/jenkins/agent/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment