{"id":13275,"date":"2019-04-01T11:01:43","date_gmt":"2019-04-01T11:01:43","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13275"},"modified":"2019-04-01T11:01:43","modified_gmt":"2019-04-01T11:01:43","slug":"how-to-sync-files-directories-using-rsync-with-non-standard-ssh-port","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-sync-files-directories-using-rsync-with-non-standard-ssh-port\/","title":{"rendered":"How to Sync Files\/Directories Using Rsync with Non-standard SSH Port"},"content":{"rendered":"<p>Today, we will be discussing about how to sync files using rsync with non-standard SSH port. You might wonder why do we need to use non-standard SSH port? It is because of security reasons. Everybody knows\u00a0<strong>22<\/strong>\u00a0is the SSH default port.<\/p>\n<div id=\"attachment_17616\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Rsync-Over-SSH-Non-standard-Port.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-17616\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/12\/Rsync-Over-SSH-Non-standard-Port.png\" alt=\"Rsync Files Over SSH Non-standard Port\" width=\"717\" height=\"344\" aria-describedby=\"caption-attachment-17616\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-17616\" class=\"wp-caption-text\">Rsync Files Over SSH Non-standard Port<\/p>\n<\/div>\n<p>So, It is mandatory to change your SSH default port number to something different which is very hard to guess. In such cases, how will you sync your files\/folders with your Remote server? No worries, It is not that difficult. Here we will see how to sync files and folders using rsync with non-standard SSH port.<\/p>\n<p>As you might know,\u00a0<strong>rsync<\/strong>, also known as\u00a0<strong>Remote Sync<\/strong>, is a fast, versatile, and powerful tool that can be used to copy and sync files\/directories from local to local, or local to remote hosts. For more details about rsync, check man pages:<\/p>\n<pre># man rsync\r\n<\/pre>\n<p>Or refer our previous guide from the link below.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/rsync-local-remote-file-synchronization-commands\/\" target=\"_blank\" rel=\"noopener\">Rsync: 10 Practical Examples of Rsync Command in Linux<\/a><\/li>\n<\/ol>\n<h3>Change SSH Port to Non-standard Port<\/h3>\n<p>As we all know, By default rsync uses default SSH port\u00a0<strong>22<\/strong>\u00a0to sync files over local to remote hosts and vice versa. We should change our remote server\u2019s SSH port to tighten the security.<\/p>\n<p>To do this, open and edit the SSH configuration\u00a0<strong>\/etc\/ssh\/sshd_config<\/strong>\u00a0file:<\/p>\n<pre># vi \/etc\/ssh\/sshd_config \r\n<\/pre>\n<p>Find the following line. Uncomment and change the port number of your choice. I recommend you to choose any number which is very hard to guess.<\/p>\n<p>Make sure you are using a unique number which is not used by existing services. Check this\u00a0<a href=\"https:\/\/www.tecmint.com\/20-netstat-commands-for-linux-network-management\/\" target=\"_blank\" rel=\"noopener\">netstat article<\/a>\u00a0to know which services are running on which TCP\/UDP ports.<\/p>\n<p>For example, here I use port number 1431.<\/p>\n<pre>[...]\r\nPort 1431\r\n[...]\r\n<\/pre>\n<p>Save and close the file.<\/p>\n<p>In RPM based systems such as\u00a0<strong>RHEL<\/strong>,\u00a0<strong>CentOS<\/strong>, and\u00a0<strong>Scientific Linux 7<\/strong>, you need to allow the new port through your firewall or router.<\/p>\n<pre># firewall-cmd --add-port 1431\/tcp\r\n# firewall-cmd --add-port 1431\/tcp --permanent\r\n<\/pre>\n<p>On RHEL\/CentOS\/Scientific Linux 6 and above, you should also update\u00a0<strong>selinux<\/strong>\u00a0permissions to allow the port.<\/p>\n<pre># iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1431 -j ACCEPT\r\n# semanage port -a -t ssh_port_t -p tcp 1431\r\n<\/pre>\n<p>Finally, restart SSH service to take effect the changes.<\/p>\n<pre># systemctl restart sshd        [On <strong>SystemD<\/strong>]\r\nOR\r\n# service sshd restart          [On <strong>SysVinit<\/strong>]\r\n<\/pre>\n<p>Now let us see how to sync files using rsync with non-standard port.<\/p>\n<h3>How to Rsync with non-standard SSH Port<\/h3>\n<p>Run the following command from the terminal to sync files\/folders using Rsync with non-standard ssh port.<\/p>\n<h5>Syntax:<\/h5>\n<pre># rsync -arvz -e 'ssh -p <strong>&lt;port-number&gt;<\/strong>' --progress --delete user@remote-server:\/path\/to\/remote\/folder \/path\/to\/local\/folder\r\n<\/pre>\n<p>For the purpose of this tutorial, I will be using two systems.<\/p>\n<h4>Remote System Details:<\/h4>\n<pre>IP Address: 192.168.1.103\r\nUser name: tecmint\r\nSync folder: \/backup1\r\n<\/pre>\n<h4>Local System Details:<\/h4>\n<pre>Operating System: Ubuntu 14.04 Desktop\r\nIP Address: 192.168.1.100\r\nSync folder: \/home\/sk\/backup2\r\n<\/pre>\n<p>Let us sync the contents of remote server\u2019s\u00a0<code>\/backup1<\/code>\u00a0folder to my local system\u2019s folder\u00a0<code>\/home\/sk\/backup2\/<\/code>.<\/p>\n<pre>$ sudo rsync -arvz -e 'ssh -p 1431' --progress --delete tecmint@192.168.1.103:\/backup1 \/home\/sk\/backup2\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>tecmint@192.168.1.103's password: \r\nreceiving incremental file list\r\nbackup1\/\r\nbackup1\/linux-headers-4.3.0-040300-generic_4.3.0-040300.201511020949_amd64.deb\r\n        752,876 100%   13.30MB\/s    0:00:00 (xfr#1, to-chk=2\/4)\r\nbackup1\/linux-headers-4.3.0-040300_4.3.0-040300.201511020949_all.deb\r\n      9,676,510 100%   12.50MB\/s    0:00:00 (xfr#2, to-chk=1\/4)\r\nbackup1\/linux-image-4.3.0-040300-generic_4.3.0-040300.201511020949_amd64.deb\r\n     56,563,302 100%   11.26MB\/s    0:00:04 (xfr#3, to-chk=0\/4)\r\n\r\nsent 85 bytes  received 66,979,455 bytes  7,050,477.89 bytes\/sec\r\ntotal size is 66,992,688  speedup is 1.00.\r\n<\/pre>\n<p>Let us check the contents of\u00a0<code>\/backup1\/<\/code>\u00a0folder in the remote server.<\/p>\n<pre>$ sudo ls -l \/backup1\/\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>total 65428\r\n-rw-r--r-- 1 root root  9676510 Dec  9 13:44 linux-headers-4.3.0-040300_4.3.0-040300.201511020949_all.deb\r\n-rw-r--r-- 1 root root   752876 Dec  9 13:44 linux-headers-4.3.0-040300-generic_4.3.0-040300.201511020949_amd64.deb\r\n-rw-r--r-- 1 root root 56563302 Dec  9 13:44 linux-image-4.3.0-040300-generic_4.3.0-040300.201511020949_amd64.deb\r\n<\/pre>\n<p>Now, let us check the contents of\u00a0<code>\/backup2\/<\/code>\u00a0folder of local system.<\/p>\n<pre>$ ls \/home\/sk\/backup2\/\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>backup1\r\n<\/pre>\n<p>As you see in the above output, the contents of\u00a0<code>\/backup1\/<\/code>\u00a0have been successfully copied to my local system\u2019s\u00a0<code>\/home\/sk\/backup2\/<\/code>\u00a0directory.<\/p>\n<p>Verify\u00a0<code>\/backup1\/<\/code>\u00a0folder contents:<\/p>\n<pre>$ ls \/home\/sk\/backup2\/backup1\/\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>linux-headers-4.3.0-040300_4.3.0-040300.201511020949_all.deb            \r\nlinux-image-4.3.0-040300-generic_4.3.0-040300.201511020949_amd64.deb\r\nlinux-headers-4.3.0-040300-generic_4.3.0-040300.201511020949_amd64.deb\r\n<\/pre>\n<p>See, both remote and local system\u2019s folders have same files.<\/p>\n<h3>Conclusion<\/h3>\n<p>Syncing files\/folders using Rsync with SSH is not only easy, but also fast and secure method. If you\u2019re behind a firewall that restricts port 22, no worries. Just change the default port and sync files like a pro.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/sync-files-using-rsync-with-non-standard-ssh-port\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we will be discussing about how to sync files using rsync with non-standard SSH port. You might wonder why do we need to use non-standard SSH port? It is because of security reasons. Everybody knows\u00a022\u00a0is the SSH default port. Rsync Files Over SSH Non-standard Port So, It is mandatory to change your SSH default &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/how-to-sync-files-directories-using-rsync-with-non-standard-ssh-port\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Sync Files\/Directories Using Rsync with Non-standard SSH Port&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13275","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13275"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13275\/revisions"}],"predecessor-version":[{"id":13276,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13275\/revisions\/13276"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}