Rsync error remote command not found

Learn how to fix bash: rsync: command not found error on your RHEL-CentOS or Ubuntu/Debian based server. Guide step by step.

Today I came across a weird problem that I’ve never seen before. While trying to migrate information from one server to another using rsync I get this error:

bash: rsync: command not found

This was the full output:

[[email protected]:~]rsync -avpr -e 'ssh -p 22' [email protected]:/home/company/public_html/* /home/company/public_html/
bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: remote command not found (code 127) at io.c(600) [receiver=3.0.6]

The problem was on the remote host, who didn’t had rsync installed.

How can I fix bash: rsync: command not found error?

Install rsync on the remote host to fix this issue.

On Ubuntu/Debian operating systems:

apt-get install rsync

On CentOS/RHEL operating systems:

yum install rsync

Output example:

[[email protected] ~]# yum install rsync
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.xfree.com.ar
* extras: centos.xfree.com.ar
* updates: centos.xfree.com.ar
Excluding Packages in global exclude list
Finished
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package rsync.i386 0:3.0.6-6.el5_11 set to be updated
--> Finished Dependency Resolution

Installing:
rsync i386 3.0.6-6.el5_11 updates 338 k

Total download size: 338 k
Is this ok [y/N]: y
Downloading Packages:
rsync-3.0.6-6.el5_11.i386.rpm | 338 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : rsync 1/1

Installed:
rsync.i386 0:3.0.6-6.el5_11

Complete!

Then run rsync again in your new server to transfer the files, it should work without issues.

[[email protected]:~]rsync -avpr -e 'ssh -p 22' [email protected]:/home/company/public_html/* /home/company/public_html/
receiving incremental file list
400.shtml
401.shtml
403.shtml
404.shtml
500.shtml

That’s all, rsync is working again and your bash: rsync: command not found should be gone.

Further reading:

  • Rsync Manual

I am trying to sync a local folder to a remote server using a non standard port and my rsync command is as follows:

rsync -avz ~/Research/Folder1/folder2 -e "ssh -p 3345" reusr@yyy.xxx.xx.xxx:/home/reusr/folder1/folder2

I am getting the following errors:

bash: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.3]

and when I run rsync --version I get

rsync  version 3.1.3  protocol version 31

I am not sure why the command not found or the subsequent errors are happening.

I am using OSX Maojave as my local machine and a Debian server as my remote machine.

asked May 3, 2019 at 7:05

Morpheus's user avatar

You local rsync needs to start a remote rsync from the SSH on the remote server but is unable to find it since it’s probably not in its path.

That’s where the «command not found» error comes from (i.e. this signifies your local rsync cannot find the remote rsync executable from the SSH session on the remote machine).

You need to find out the path of rsync on the remote server and make that part of your rsync parameters. The parameter you need to add is:

--rsync-path=/path/to/remote/rsync

Where /path/to/remote/rsync is the location on the remote server of the rsync command. Since your remote rsync server runs on Debian, this will probably be /usr/bin/rsync

So your rsync command becomes:

rsync -avz ~/Research/Folder1/folder2 -e "ssh -p 3345" --rsync-path=/path/to/remote/rsync reusr@yyy.xxx.xx.xxx:/home/reusr/folder1/folder2

answered May 3, 2019 at 7:55

StarCat's user avatar

StarCatStarCat

1,1461 gold badge6 silver badges12 bronze badges

Make sure rsync is also installed on the remote machine you are trying to access. In my case, I was getting this error on the local machine on which it was installed, because rsync wasn’t installed on the remote server.

answered Sep 5, 2021 at 16:02

James's user avatar

JamesJames

1212 bronze badges

There is a lot of good information around about this problem, including the answer above. But in my case, I am an administrator on both the source and destination machines, and I wished to understand what was going on and what «right» configuration options would make this problem go away. I haven’t been entirely successful but it seems likely that others may find this information useful.

As the answer above states, rsync may be in the path on the remote machine when running an interactive shell, but not when running rsync by ssh. As Siddesh notes at http://siddesh-bg.blogspot.com/2009/02/rsync-command-not-found-error-even.html this can be solved by explicitly specifying the path to the remote rsync from your local shell:

rsync -av --rsync-path=/usr/local/bin/rsync -e "ssh -l ssh-user" /source server:/destination

But as an administrator I wanted to fix the problem, not just work around it. OldSchool posted a useful troubleshooting approach at https://groups.google.com/group/comp.unix.solaris/browse_thread/thread/0a06a4d382d752d8?pli=1

He suggest you find out what shell is being run for you on the remote machine, then what PATH has been established there:

ssh user@host 'echo $SHELL' 
ssh user@host 'echo $PATH' 

Tom Feiner has a nice post at Why does an SSH remote command get fewer environment variables then when run manually? that discusses the environment establishment of the SSH command execution shell.

OldSchool also noted that «man sshd_config» provides some information about how an ssh session gets an environment. The sshd_config setting «PermitUserEnvironment» can be set to allow a user’s ~/.ssh/environment on the server side and environment options in the AuthorizedKeysFile file to be processed by sshd. The default is no.

So with default sshd_config settings the path is going to be built by your default shell. If your ssh command requests an interactive session (ssh user@host) then on the remote server the default shell will do an interactive login, which will probably result in the PATH that you expect. But if you are initiating an ssh session for rsync (rsync -av —rsync-path=/usr/local/bin/rsync -e «ssh -l ssh-user» /source server:/destination) then the remote server gives you a SSH command execution shell that is a non-interactive shell. In my case, the remote non-interactive shell (bash) is not executing /etc/profile, because it only does that for interactive shells or non-interactive shells with the —login option. I could force it like this:

ssh user@host 'echo $PATH;source /etc/profile;echo $PATH' 

I also studied Daniel Barrett & Richard Silverman’s «SSH The Secure Shell» (O’Reilly 2001) and set a PATH in /etc/ssh/sshrc that I hoped would make rsync available to SSH command execution shells, but, /etc/ssh/sshrc is executed before the users shell or command is invoked, and apparently it’s environment is not passed on to that shell or command.

At this point I am going to be satisfied with the rsync command line option, i.e.:

rsync -av --rsync-path=/usr/local/bin/rsync -e "ssh -l ssh-user" /source server:/destination

because I am concerned that if I change the sshd_config setting «PermitUserEnvironment» then I will probably fail a security audit on my servers. I may revisit this after I have more experience with our organization’s security audits.

Знаменитый RSYNC имеет множество полезных применений. Часто используется полная схема взаимодействия (RSYNC-сервер <===> RSYNS-клиент), но это вовсе не обязательно.

Например, в случае бекапирования данных с локального сервера source.king.org (т.е. где запускается команда rsync) на удалённый сервер target.king.org достаточно использовать лишь RSYNC-клиент.


1. В данном примере мы «толкаем» контент с локального сервера на удалённый:
Сервер-Источник = source.king.org
Сервер-Получатель = target.king.org

 [source.king.org ~]$ rsync -e ssh -avHP  /home   root@target.king.org:/mnt/backup/

-e ssh — копировать по протоколу SSH (этот параметр может быть не обязателен, копирование и так пойдёт по SSH).
Слеш в конце пути получателя обязателен.


2. В данном примере мы «тащим» контент с удалённого сервера на локальный, при этом команду выполняем на локальном:
Сервер-Источник = source.king.org
Сервер-Получатель = target.king.org

rsync -e "ssh -p 30022" -avH   root@target.king.org:/home  /mnt/backup/

Обратите внимание, что в пути источника после каталога /home слеш намеренно не поставлен.
Благодаря этому каталог home на получателе создаётся автоматически.

Но вот что самое интересное — во втором случае клиент rsync должен быть проинсталлирован не только на локальном сервере, что вполне понятно, но и на удалённом сервере, иначе при выполнении данной команды будет выполняться ошибка

  1. bash: rsync: команда не найдена

  2. rsync: connection unexpectedly closed (0 bytes received so far) [receiver]

  3. rsync error: remote command not found (code 127) at io.c(600) [receiver=3.0.6]

Оказывается, что при работе Rsync по протоколу SSH последний запускает на удаленном компьютере копию Rsync с ключом —server , т.е. в режиме сервера.
Следовательно, здесь работа идет так, как если бы на удаленном компьютере запускался Rsync-демон, поэтому и здесь также достигается максимальная производительность, свойственная технологии «клиент-сервер».

Но ни один дятел, описывающий применение rsync, не упомянул этот важный момент.

Еще нужно отметить, что использование здесь SSH является весьма прожорливым.
Например, процессор Atom при копировании загружен на 100%, а скорость по сети падает от 100 до 20 Mbps.

Понравилась статья? Поделить с друзьями:
  • Rrdc update error var lib rrdcached db pve2 node pve 1
  • Rr 4035 sql error
  • Rqt close как исправить
  • Rqt close odin ошибка
  • Rptwin is not installed как исправить