mv: cannot move
Tried to rename (mv) a directory owned by fin under /backup, but it failed with permission denied.
[fin@test ~]$ cd /backup
[fin@test backup]$ ls -l
total 0
drwxr-xr-x 2 fin fin 6 Jan 5 07:32 directory
[fin@test backup]$ mv directory directory_2
mv: cannot move 'directory' to 'directory_2': Permission denied
Permission denied is because the current directory /backup belongs to other user which is erp in this case. So the user is not permitted to rename its underlying directories.
Let's see a more detailed list.
[fin@test backup]$ ls -al
total 0
drwxr-xr-x 3 erp erp 25 Jan 5 07:47 .
dr-xr-xr-x. 20 root root 280 Jan 5 07:28 ..
drwxr-xr-x 2 fin fin 6 Jan 5 07:32 directory
As you can see, the current directory represented by a single dot is owned by other user erp, not the current user fin.
Solutions
There're 2 ways to solve the prohibition.
Add a WRITE permission to OTHER
We use root to add a permission on the directory.
[root@test ~]# chmod o+w /backup
In which, o means OTHER and w means WRITE permission.
We list the current directory again.
[fin@test backup]$ ls -al
total 0
drwxr-xrwx 3 erp erp 25 Jan 5 07:47 .
dr-xr-xr-x. 20 root root 280 Jan 5 07:28 ..
drwxr-xr-x 2 fin fin 6 Jan 5 07:32 directory
As you can see, we add a w to others on the current directory. Alternatively, you may use 777 instead of o+w.
The drawback of this method is that the current directory is widely open to anonymous users, the folder security could be compromised, so I think we still need a better solution.
Change Ownership
We change the ownership to the user who needs to rename the underlying directories. That is to say, we make the user take control over the current directory /backup.
[root@test ~]# chown fin:fin /backup
We list the current directory again.
[fin@test backup]$ ls -al
total 0
drwxr-xr-x 3 fin fin 25 Jan 5 07:59 .
dr-xr-xr-x. 20 root root 280 Jan 5 07:28 ..
drwxr-xr-x 2 fin fin 6 Jan 5 07:32 directory
Both ways make the user have the permission to change the underlying objects by mv command.
[fin@test backup]$ mv directory directory_2
[fin@test backup]$ echo $?
0
We made it.