I want rsync with sudo.
1 I try solution from this topic:
huser@linux:~$ rsync -avz --stats --rsync-path="echo 4321 | sudo -Sv && sudo rsync" /home/huser/mylibs/ ruser@192.168.0.100:/home/ruser
ruser@192.168.0.100's password:
I am confused - rsync shouldn't ask for a password, should it? Ok, I type ruser's password and get error:
[sudo] password for ruser: sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(231) [sender=3.2.7]
Where
ruser is my username in remote Ubuntu 22,
huser is my username in host Ubuntu 22,
4321 is ruser's password (for me ok to keep it in history),
192.168.0.100 is remote machine IP.
2 I try another way, I have ssh key:
rsync --rsync-path="sudo -S rsync" -rvz -e "ssh -i /home/huser/key/my_ssh_key" --progress /home/huser/bin/ ruser@192.168.0.100:/home/ruser/
[sudo] password for ruser: 4321
And I wait a while for a folder of several bytes to transfer... but nothing happens, not even an error.
3 Let's check that rsync can work without sudo:
rsync -avz --stats /home/huser/mylibs/ ruser@192.168.0.100:/home/ruser
This works ok.
How I can work with sudo?
ruser@192.168.0.100's password:
Then I in password 1234 then I see[sudo] password for ruser: sending incremental file list ./ testfile.txt
And script doesn't finish, I should manually stop it using Ctrl+C. I am confused why rsync again ask password that I already have wrote to script? And how finish automatically? – Андрей Тернити Mar 01 '24 at 12:07rsync -avz -e "ssh -p 22 -i \"/home/huser/key path with space/my_ssh_key\"" --stats --rsync-path="{ echo 4321; cat; } | sudo -S rsync" /home/huser/mylibs/ ruser@192.168.0.100:/home/ruser
Now don't ask password. But how remove my password from script in case of key? And script doesn't finish automatically again... Thank you – Андрей Тернити Mar 02 '24 at 10:36