Problem
I tried to copy a file from one Linux server dbappweb to another Linux server dbappweb1 but got the error ‘Permission denied’. I tried to copy the file using the SCP command over ssh.
[root@dbappweb public]# scp -p PKIServer.zip user1@dbappweb1:/home/user1/ user1@dbappweb1's password: scp: /home/user1/PKIServer.zip: Permission denied
Reason
I got the “Permission denied’ error because that file was already at the destination location with read-only permission for the group and others. Due to the read-only permission files existing at the destination location not becoming replaced by the new file when I tried to copy the file through SCP.
[root@dbappweb1 user1]# ll PKIServer.zip -rw-r--r-- 1 user1 user1 4855173 Feb 28 12:27 PKIServer.zip
Solution 1
- First, delete the file existing at the destination location.
[root@dbappweb1 user1]# rm PKIServer.zip rm: remove regular file `PKIServer.zip'? y [root@dbappweb1 user1]#
- Now copy the file using scp command and it will be copied to the destination.
[root@dbappweb public]# scp -p PKIServer.zip user1@dbappweb1:/home/user1/ user1@dbappweb1's password: PKIServer.zip 100% 4741KB 4.6MB/s 00:00 [root@dbappweb public]#
Solution 2
- Change the permission of the file from read-only to read-write for groups.
[root@dbappweb1 user1]# chmod 664 PKIServer.zip [root@dbappweb1 user1]# ll PKIServer.zip -rw-rw-r-- 1 user1 user1 4855173 Feb 28 12:27 PKIServer.zip
- Now copy the file using scp command and it will be copied to the destination.
[root@dbappweb public]# scp -p PKIServer.zip user1@dbappweb1:/home/user1/ user1@dbappweb1's password: PKIServer.zip 100% 4741KB 4.6MB/s 00:00 [root@dbappweb public]#
Note: In the above case both servers were RHEL 5.8.