scp files

Need assistance

I have ssh keys exchanged between servers for user ZID

ssh works without password between ZID . "ssh SERVER A to SERVER B works"

I have a property file on SERVER A which is owned by root and I need to transfer the file changing into ZID user and transfer to SERVER B

wanted to automate using a script . Need inputs on how I can accomplish this task .

I cannot tell you what you need precisely. Your question needs help

Basically -
If you have sudo, set up your account to have ZID access, no password required.

sudo - ZID -c "scp /path/local/to/filename serverB:/path/to/file/filename"

If ZID does not have root access on serverB you have other problems to solve. Same as if ZID has no access to the file on serverA.

However, let's go with this. If you have questions:
Please tell us your UNIX/Linux sysyem type ( uname -a works well)
It will help us to help you.

1 Like

Also, just because a file is owned by root, does not mean that only root can access it! What are its permissions?

Below command works . here is the solution

root@serverA:/var/tmp# sudo -u ZID scp /var/tmp/samplescp.txt serverB:/var/tmp
samplescp.txt        100% |******************************************************************************************|    54       00:00

Question still stands, what are its permissions? That might not be the simplest solution

Corona688. You were correct when the file has root permission it cannot be transfered , file persmison is 755 root:root.

So In the script we changed the permission of the file to ZID and then using the above command worked. :b::b::b::b::b:

A 755 file can be read, and even executed, by anyone. That was not the problem.

Perhaps the destination file permissions were the problem? Unfortunately, with it having now been overwritten by a potentially new user and new set of permissions already, it is now impossible to answer my question. Keep an eye on whatever uses that file to make sure it's okay with this ownership and permissions.

In the future, "trying users until they work" is not a terrific idea, if you post the file owners and permissions we can tell you in 2 seconds what's preventing a file from being read or overwritten.

Sure Thank you Corona688