1

I have 3 machines in my local network. These are

Machine1 : 192.168.1.1 (root user: user1)
Machine2 : 192.168.1.2 (root user: user2) 
Machine3 : 192.168.1.3 (root user: user3)

I am working on Machine1. Other machines (2 and 3) my remote machines. I reach my remote machines using ssh command from Machine1. I have not any direct access to Machine2 and Machine3 other than network-ssh connection.

I want to copy some files that are located on /usr/local/lib path in Machine2 to /usr/local/lib path of machine 3.

For this purpose from my main machine Machine1 when I used the command:

scp [email protected]:/usr/local/lib/my_file [email protected]:/usr/local/lib/my_file

I get the error :

Permission denied, please try again.

Permission denied, please try again.

Permission denied (publickey,password).

After encountering this error I used another method. From my main machine Machine1, I connect Machine2 with ssh connection. From ssh connected Machine2 I used the command:

scp /usr/local/lib/my_file [email protected]:/usr/local/lib/my_file

I get the error:

scp: /usr/local/lib/my_file: Permission denied

From ssh connected Machine3 I used the command:

scp [email protected]:/usr/local/lib/my_file /usr/local/lib/my_file

I get the same error:

scp: /usr/local/lib/my_file: Permission denied

I have tried 3 different method to copy some file in /usr/local/lib path. However I couldn't achieve copy.
How can I copy files, which are located in /usr directory, between 2 remote machines?

2
  • Likely issue is that /usr/local/lib has permissions set up such that user3 cannot write directly to it.
    – QIS
    Commented Oct 9, 2019 at 20:29
  • What is actually happening is that Machine2 and Machine3 don't have ssh access to each other. That is why you are getting Permission denied (publickey,password). You'll need to enable ssh access between Machine2 and Machine3 and make sure that the user with whom you are connecting has write access to /usr/local/lib on both machines. Commented Oct 9, 2019 at 21:37

1 Answer 1

3

I believe the reason you are getting the error is that the regular users do not have the correct permissions set in order to read, write or execute the files you are trying to copy.

I created 2 files, /root/FileByRoot and /home/admin/FileByAdmin.

$ ll /root/FileByRoot
-rw-r--r-- 1 root root 13 Oct 10 00:43 /root/FileByRoot

$ ll /home/admin/FileByAdmin
-rw-rw-r-- 1 admin admin 19 Oct 10 00:43 /home/admin/FileByAdmin

Now, here is what I get when I try to copy them using the admin user to another machine.

$ scp -P 2220 [email protected]:/root/FileByRoot /home/heysus/
[email protected]'s password:
scp: /root/FileByRoot: Permission denied

$ scp -P 2220 [email protected]:/home/admin/FileByAdmin /home/heysus/
[email protected]'s password:
FileByAdmin                                                                           100%   19     0.5KB/s   00:00

$ ll /home/heysus/FileByAdmin
-rw-rw-r-- 1 heysus heysus 19 Oct 10 00:56 /home/heysus/FileByAdmin

Now let's move the file to a directory where admin has full control.

$ mv FileByRoot /home/admin/FileByRoot

Since admin has permissions to the folder, I now can copy it.

$ scp -P 2220 [email protected]:/home/admin/FileByRoot /home/heysus/
[email protected]'s password:
FileByRoot                                                                            
100%   13     0.3KB/s   00:00

In conclusion, enable the root user on your /etc/ssh/sshd_config file and copy the necessary files via the root user. Once you are done, disable root login in the /etc/ssh/sshd_config.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .