Permission Denied Error While Copying Ubuntu

When copying files in the Ubuntu Linux operating system using either the graphical method or the "cp" command, you may get a "permission denied" error. This happens for two reasons: you either don't have permission to move the actual file or you don't have permission to write to the directory you are copying the file into. Each file or directory has separate permissions set for the owner of file or directory, the group the file or directory belongs to and all other users (the world).

  1. File Permissions

    • Each file and directory in the Ubuntu Linux file system has a specific set of permissions which determine the user or users who allowed to copy it. Some files and directories can be copied by any user, others can only be copied by the user that created them, and still others can only be copied by the root user. In the Linux operating system, the root user has a special account that is allowed complete access to the system. All other users are limited in what changes they can make to the system.

      You can view the owner of the file or directory, and the permissions for each user type, by typing "ls -l" at a command prompt. This command will list the contents of the directory you are currently working in. To view the permissions of all of the files and directories in the file system, type "ls -l /" at the command prompt.

    Ubuntu Root User

    • The Ubuntu Linux operating system has a root user, just like all of the other Linux and Unix distributions. The Ubuntu root user does not have a password associated with the account. Instead, at least one of the regular users has administrative privileges. These privileges allow the user to override file permissions, if necessary. For example, the administrator can copy or make changes to files and directories owned by the root user.

    The sudo Command

    • The "sudo" command is used to execute a command as another user. Ubuntu users use the "sudo" command to act as the root user. This allows the user to access directories that are normally restricted. It also gives the user the ability to execute commands that can only be executed by the root user.

      If you get a "permission denied" error when you are copying a file to a directory, type the command sudo in front of the command. The syntax is

      sudo cp filename dir_name/

    The chown Command

    • If someone other than the root user owns the directory, you can change the ownership using the "chown" command. You can also change the ownership of files and directories owned by root, but this is not recommended by the Linux developers. These files and directories contain system configuration information and other files not meant to be accessed or edited by normal users. Also, the operating system expects certain files and directories to be owned by root. If the ownership changes, the system may not work correctly.

      The syntax of the "chown" command is

      chown user_name dir_name/

      where the "user_name" is the user name of the person you want to give ownership to and "dir_name" is the name of the directory or file you want to change the ownership for. A regular user can change the ownership for a file or directory he owns. If you want to change the ownership of a file you do not own, type "sudo" before the command.



View Blog Post

Geek Vs Geek: Windows 10: Should You Want Microsoft’s Next Contentious OS?