Advertisement
efxtv

Rsync linux command tutorial

Jun 14th, 2025
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | Cryptocurrency | 0 0
  1. Rsync Linux Commands:
  2.  
  3. ##################################################################
  4. Join our telegram channel for more : https://t.me/LinuxClassesEFXTv
  5. ##################################################################
  6.  
  7. Q. What is RSYNC and how to use it to Synchronize files in Linux servers?
  8. - rsync is a powerful and versatile Linux command for transferring and synchronizing files between local and remote servers. This approach reduces bandwidth usage and speeds up transfers.
  9.  
  10. Objective: To Synchronize file files on the Remote server in such a way that we are not required to copy them one by one. Easy access and less effort to copy and paste remotely.
  11.  
  12. # Dependencies are
  13. -ssh
  14. -Local and remote machines should have rsync installed
  15.  
  16. # Sonfigure ssh SH ssh key no password
  17. $ ssh-keygen (hit enter to set no password)
  18. $ ssh-copy-id -i ~/.ssh/id_rsa.pub userForKali@IPaddressForKali
  19.  
  20. # Create a config folder in .ssh
  21. $ touch ~/.ssh/config
  22. $ chmod u=--- ~/.ssh/config
  23. $ chmod u=rw- ~/.ssh/config
  24.  
  25. # Paste these in the config file
  26. host nameanything
  27. hostname 192.168.1.40
  28. port 22
  29. user devil
  30. IdentityFile ~/.ssh/id_rsa
  31.  
  32. # Edit file /etc/ssh/sshd_config and add two lines at the end of the file
  33. PubkeyAuthentication yes
  34. PasswordAuthentication no
  35.  
  36. # Basic Syntax of rsync
  37. rsync [OPTIONS] SOURCE DESTINATION
  38.  
  39. # List the files in the local machine using rsync
  40. $ rsync files_directory_name
  41.  
  42. # List the files in a remote machine
  43. $ rsync [email protected]:~/devil/files
  44.  
  45. # Sync a directory to another directory or location in a local machine only
  46. -a: Archive mode
  47. -v: Verbose mode
  48. -h: Human-readable output
  49. rsync -avh localfolder localfolder2
  50.  
  51. # Copy files (demo mode, it will check for errors)
  52. $ rsync --dry-run files [email protected]:~/home
  53.  
  54. # Copy files (demo mode, it will check for errors)
  55. -r recursively
  56. -v verbose
  57. $ rsync -rv --dry-run files [email protected]:~/devil
  58.  
  59. # copy without dry-run
  60. $ rsync -rv files [email protected]:~/devil
  61.  
  62. # Delete everything from your computer
  63. rm files/*
  64.  
  65. # Copy from a remote server to the local system
  66. $ rsync -rv [email protected]:~/devil/files/ files/
  67.  
  68. # Rename the file into local machine and sync again, it will keep both of the files by default
  69. $ rsync -rv --dry-run files [email protected]:~/devil
  70.  
  71. # Delete all the old files from the remote server and copy new files
  72. $ rsync -rv --delete files [email protected]:~/devil
  73.  
  74. # Check the files ls -l time has been modified on a remote server
  75. # Time sync keep same time using
  76. -a - archive mode
  77. $ rsync -rva --delete files [email protected]:~/devil
  78.  
  79. # Copy the files from the local to the remote server but
  80. # Delete the files from the local machine once its sent
  81. $ rsync -rva --remove-source-files files [email protected]:~/devil
  82.  
  83. [ BONUS COMMANDS ]
  84. How to connect to termux shell using SSH
  85.  
  86. # Install ssh
  87. $ pkg install openssh
  88.  
  89. # Change password
  90. $ passwd
  91.  
  92. # Start ssh in termux
  93. $ sshd
  94. # copy the username
  95. whomi
  96.  
  97. # Come to kali shell or ubuntu
  98. $ ssh -p 8022 [email protected]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement