I need to copy a file from local to remote server. I am using rsync for this with passwordless connection. I am not able to change permissions for the file after migration.
I am using this command.
rsync -ab --suffix _BKP"$(date +%Y%d%m)" --perms --chmod=ug+rwx,o+rx --chown=sai:sai /home/yesh/yesh_final_V1.sh [email protected]:/data001/yesh
yesh is also a super user. My rsync version is rsync-3.1.1-1.el7.rfx.x86_64.
Am I doing anything wrong? If so please correct me. Or is there any other way to change permissions on remote server using sudo user?
Note: I don't want to login into server and change. I need this to be done from my local itself, kind of running from a script.
Normally, it would be sufficient to just use ssh directly, for one-off implementation.
One-Off Operation
as long as yesh is super-user and you know the password for yesh, you can do the following to update over ssh.
ssh as yesh (assumes you have the password).
ssh [email protected]
Change to make script executable
Ubuntu> sudo chmod 755 /home/yesh/yesh_final_V1.sh
Scripted Operation
The author of the question commented that they wish to do this in scripted form. To achieve this, you can use the "sshpass" functionality, which has to be present on the host computer.
sudo apt-get install sshpass
To use it, you may find the below bash script example useful:
function scripted_remote_operation { sshpass -f password.txt ssh -o StrictHostKeyChecking=no -t -t [email protected] -o StrictHostKeyChecking=no <<EOF sudo chmod 755 /home/yesh/yesh_final_V1.sh exit EOF }
This can be executed from the host computer as part of a script, automatically logging in, making the change as requested. Unfortunately, this will require that the password requirement for users with admin privileges, be disabled (NOT RECOMMENDED).
For example, in the directory
/etc/sudoers.d
You could include the file
010_ubuntu-nopasswd
with the contents
root ALL=(ALL) NOPASSWD: ALL
This information is provided for clarity only. It is absolutely not a good idea to disable the sudo password on a machine.
Possible Answer Without sudo on the remote machine
If the file is installed remotely with yesh as the owner, then the chmod operation can happen without elevated privileges, and the chown operation can be included in the same sshpass script.