43

I want copy to /lib/udev but gives error

cp -f /tmp/ok_pcscd_hotplug.sh /lib/udev

cp:cannot create regular file /lib/udev/ok_pcscd_hotplug : Permission denied

I am root , but I can't understand . what can I do ?

Cristian Ciupitu
  • 167
  • 1
  • 16

5 Answers5

41

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 /tmp/ok_pcscd_hotplug.sh /lib/udev/.

otherwise you have to use sudo:

sudo cp -f /tmp/ok_pcscd_hotplug.sh /lib/udev/.

If you're still not able to write to the directory, then it is possible that:

  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're in the latter case, edit the file /etc/fstab.

girardengo
  • 5,005
4

Its not necessary every time that you need to be root for this purpose So if you want to do it with root user its fine, but if you want to do it without root, then you have 2 options:

  1. Check the permissions of file. You must have read permissions to that
  2. Check that file or link with same name is not present in the destination directory. Because if link with same name is there in destination directory, it won't allow you to do that and also will not warn that link with same name is present
3

You should create directory first if /lib/udev doesn't exist

mkdir -p /lib/udev
1

Try cp /tmp/ok_pcscd_hotplug.sh /lib/udev/ in root user.

Sambit
  • 1,264
0

First do " ls -l " and check the permissions for this directory. If you see something like -rw-r--r-- , that means Owner can read-write, Usergroup can only read, World can only read. Type in the following command if this be the case : " chmod 766 ". This will allow you to perform read-write operations on that file. Now try copying that file the same way. It should work