MENU

cp – cannot create regular file : permission denied (root)

Here is the solution for the unexpected error cp – cannot create regular file : permission denied even when the user is logged into ubuntu or other linux server as root.

[root@server]# sudo cp /home/login.css /usr/local/itplore/htdocs/admin/design/img
cp: cannot create regular file ‘/usr/local/itplore/htdocs/admin/design/img/login.css’: Permission denied
[root@server]# sudo cp -f /home/login.css /usr/local/itplore/htdocs/admin/design/img
cp: cannot remove ‘/usr/local/itplore/htdocs/admin/design/img/login.css’: Permission denied

Solution:

Check if you are really superuser with:

whoami

if the output is root, then you are superuser and you can make the copy of the file with:

cp -f /home/login.css /usr/local/itplore/htdocs/admin/design/img

otherwise you have to use sudo:

sudo cp -f /home/login.css /usr/local/itplore/htdocs/admin/design/img

However in the above actual case the user is logged in as root, but cannot copy. So in this case you can skip the above steps and try the below steps.

  1. the directory has the immutable flag enabled. check with lsattr.
  2. the directory is mounted with read-only permissions: type in terminal:cat /proc/mounts (or mount or cat /etc/mtab)and check the output, if directory is mounted read-only.

If you are in the first case, change the directory attributes with chattr;

  • remove immutable flag on file or directory chattr -i <file/dir>
  • adding immutable flag on file or directory again chattr +i <file/dir>

If you take the actual case as an example, then try the following as superuser or root.

chattr -i /usr/local/itplore/htdocs/admin/design/img/
chattr -i /usr/local/itplore/htdocs/admin/design/img/login.css
sudo cp -f /home/login.css /usr/local/itplore/htdocs/admin/design/img

If you’re in the latter case, edit the file /etc/fstab.

If this helps to solve your permission denied issue, please share it.

Screenshot Image of Ubuntu Linux Cloud Server Admin Root Login

Ubuntu Linux Cloud Server Admin Root Login by Pratish

Note: The above given screenshot is taken as a sample for Ubuntu Linux Cloud Server Root (Admin) Login done by me. The client who own this cloud server has not subscribed for monthly maintenance service or any other updation service. That’s why there are many updates available on the server. I also offer cloud server installation for a onetime payment fee. You can subscribe to my monthly maintenance plans for better server security and performance. Please contact me for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *