0

When I copy a file using scp from a remote location to the /tmp/ directory in local machine, it is successful. However, when I copy another file using scp from the same machine(i.e. remote and local machines are same), I am getting the 'Permission denied' error.

scp user@host-b:/usr/U91/host-b/trace/server_console_host-b.trc /tmp is successful.

scp user@host-a:/usr/U91/host-a/trace/server_console_host-a.trc /tmp fails with error: /tmp/server_console_host-a.trc: Permission denied

Even normal copy fails: cp /usr/U91/host-a/trace/server_console_host-a.trc /tmp/ cp: cannot create regular file ‘/tmp/server_console_host-a.trc’: Permission denied

I am unable to understand why scp from remote is successful while others fail.

Note: All the above commands are executed in host-a machine.

Krishna Chaurasia
  • 8,924
  • 6
  • 22
  • 35
  • I identified the issue. There was already a file with same name in /tmp that belonged to a different owner so the scp failed since it did not have the permission to overwrite the existing file due to different user. scp worked correctly after removing the file from /tmp. – Krishna Chaurasia Jan 01 '19 at 11:25

2 Answers2

0

Is it possible that you have done some changes to the owner ship of /tmp on host-a?

/tmp should look like this...

ls -la / |grep tmp
**drwxrwxrwt.**  16 root root  4096 Dec 31 11:05 tmp

May something for you to read about. ;-) https://askubuntu.com/questions/432699/what-is-the-t-letter-in-the-output-of-ls-ld-tmp

terpentin
  • 1
  • 1
  • `drwxrwxrwt 356 root root 122880 Dec 31 05:20 tmp`. Also, I believe all the above commands I mentioned uses the same /tmp directory, so why it would work for one and not for others is I am unable to understand. – Krishna Chaurasia Dec 31 '18 at 10:22
  • May I ask to show us the permission for that file on each host? What makes me wonder is the following line: Even normal copy fails: cp /usr/U91/host-a/trace/server_console_host-a.trc /tmp/ cp: cannot create regular file ‘/tmp/server_console_host-a.trc’: Permission denied – terpentin Dec 31 '18 at 10:30
  • Both are same: `-rw-r--r-- 1 user sys 203529 Dec 29 11:54 server_console_host-a.trc` for host a and `-rw-r--r-- 1 user sys 3791296 Dec 31 05:31 server_console_host-b.trc` for host b. – Krishna Chaurasia Dec 31 '18 at 10:34
  • strange...does it work as another user or to a different target (like users home DIR)? – terpentin Dec 31 '18 at 11:30
  • 1
    I identified the issue. There was already a file with same name in /tmp that belonged to a different owner so the scp failed since it did not have the permission to overwrite the existing file due to different user. scp worked correctly after removing the file from /tmp. – Krishna Chaurasia Jan 01 '19 at 11:26
0

for /tmp directory if you will check the access by using ls -l (running at parent of tmp),

you will be getting rwxrwxrwt

or

in simple way you don't have execute permission so that you can perform delete/override operation inside directory using scp command.

In this case let /tmp folder already contains the file with same name which you want to copy then for this override operation will be done and you do not have that permission.

Solution 1: Rename your local file which is to be copied at server and use updated file name in your command.

or

Solution 2: Rename/remove the file (which has same file name as local) from /tmp.

or

Solution 3: Give execute access to the account which you are using.

Abhishek Kumar
  • 820
  • 10
  • 18