Linux write permission to all

How do I set read/write permissions my hard drives?

I’ve recently installed Ubuntu 11.10 on my laptop, but I can’t do anything with my 1.5TB external drive, and my 500GB because I don’t have write permission. Are there any specific commands I can use in the terminal to set the read/write permissions?

The external is NTFS, and the 500GB is ext4.

11 Answers 11

for your 500 GB hard-drive (ext4) filesystem, you need to give the write and execute permission on /media/username/your_drive partition:-

Brief Explanation:

sudo :- it will elevate your priviledges to execute the command.

chmod:- command to change the permissions

u :- user

g:- group

o :- other

/media/username/your_drive :- partition

For your NTFS partition please follow fossfreedom’s advice.

Hope this is helpful.

If you don’t mind the security problems you can do a recursive chmod in order to change the permissions of all the files.

Also if your files were created in another OS like windows they will have different ownership you can do the same as above to change the ownership of the files

Thats the way I solved a similar problem for my friend after migrating from windows and also after migrating from Linux Mint to Ubuntu.

To fix read/write issue ntfs, just install these packages:

when installed, in the dash, type in and run: ntfs-config enter your password when prompted, and then you can enjoy read/write support for ntfs file systems.

Don’t mark all your files as executable as some answers suggest. Use 755 for directories and 644 for files. This will set the x bit for directories in order to list their contents but not for files.

I had the same problem and solved it with nautilus as root.

if nautilus is not installed:

Before running nautilus make sure the partition or hard disk is mounted.

Run nautilus as root with

Your partition or hard disk should appear on the left.

Right click on it -> select «Properties»

In the new window that appears, select the «Permissions» tab. From here you can change the owner if you need to, as well as the permission for a certain user, root, or others.

I was having a hard time solving the problem and this solution worked for me

install physical storage device manger:

Open storage device manger:

Choose your required drives

  • Press assist
  • Uncheck open as read only
  • Check owner user of file system and write your username
  • Press ok and apply
  • Remount the drive
  • Note: if you can’t change files to binary executables, go to special files and check permit execution of files as binaries, and go to step 7

    Using Terminal (Use this when you are currently logged in Ubuntu):

    Quickly open the terminal or press Ctrl Alt T

    First you need to find out the partition’s name which you want to access, run the following command:

    Then run this command in your terminal, to access your drive in read/write mode.

    OR Run this command (if the previous didn’t work)

    I formatted my extended partition using GParted and the resulted drive had only root level access. In order to grant access to my username, I executed below command.

    I look around the forum for answers.

    I have 3 users, «user1″ ,»user2», «user3»:

    • user1 : is sudo user with most of the access
    • user2 : is also sudo user with less access
    • user3 : is just another user with no sudo access

    Im trying to give access to partitions 1 and 2 to user1, user2 and user3 . The owner of the partition is root. the partitions are mounted at

    Note : I tried to mount the partition using

    Which created the directory to mount the partitions.

    • (I dont know this worked or not)
    • Used nautilus as root.
    • if nautilus is not installed: sudo apt-get install nautilus
    • Before running nautilus make sure the partition or hard disk is mounted.

    Run nautilus as root with

    Your partition or hard disk should appear on the left.

    Right click on it -> select «Properties»

    In the new window that appears, select the «Permissions» tab.

    Kept the owner as «root» and group as «user1» with read and write access for both owner and group.

    From here you can change the owner if you need to, as well as the permission for a certain user, root, or others.

    Note: The user1 ,user2 and user3 did not get access to the partitions yet

    Step 2: Added User2 and user3 to group «user1».

    Went to the last line entered:

    Saved and Exited

    Note: Now i am able to read and write files to the partitions 1 and 2.

    Only issue is, if i have logged into user1 , then try to access partition 1 from user2 , it is not accessible.

    And access partition 1 from user2.

    I don’t know if this is the right way to do it. Just combined many responses and did. Somehow its working.

    Источник

    File Permissions in Linux/Unix: How to Read/Write & Change?

    Updated October 7, 2021

    Linux is a clone of UNIX, the multi-user operating system which can be accessed by many users simultaneously. Linux can also be used in mainframes and servers without any modifications. But this raises security concerns as an unsolicited or malign user can corrupt, change or remove crucial data. For effective security, Linux divides authorization into 2 levels.

    In this Linux file commands tutorial, you will learn-

    The concept of Linux File permission and ownership is crucial in Linux. Here, we will explain Linux permissions and ownership and will discuss both of them. Let us start with the Ownership.

    Click here if the video is not accessible

    Ownership of Linux files

    Every file and directory on your Unix/Linux system is assigned 3 types of owner, given below.

    A user is the owner of the file. By default, the person who created a file becomes its owner. Hence, a user is also sometimes called an owner.

    Group

    A user- group can contain multiple users. All users belonging to a group will have the same Linux group permissions access to the file. Suppose you have a project where a number of people require access to a file. Instead of manually assigning permissions to each user, you could add all users to a group, and assign group permission to file such that only this group members and no one else can read or modify the files.

    Other

    Any other user who has access to a file. This person has neither created the file, nor he belongs to a usergroup who could own the file. Practically, it means everybody else. Hence, when you set the permission for others, it is also referred as set permissions for the world.

    Now, the big question arises how does Linux distinguish between these three user types so that a user ‘A’ cannot affect a file which contains some other user ‘B’s’ vital information/data. It is like you do not want your colleague, who works on your Linux computer, to view your images. This is where Permissions set in, and they define user behavior.

    Let us understand the Permission system on Linux.

    Permissions

    Every file and directory in your UNIX/Linux system has following 3 permissions defined for all the 3 owners discussed above.

    • Read: This permission give you the authority to open and read a file. Read permission on a directory gives you the ability to lists its content.
    • Write: The write permission gives you the authority to modify the contents of a file. The write permission on a directory gives you the authority to add, remove and rename files stored in the directory. Consider a scenario where you have to write permission on file but do not have write permission on the directory where the file is stored. You will be able to modify the file contents. But you will not be able to rename, move or remove the file from the directory.
    • Execute: In Windows, an executable program usually has an extension “.exe” and which you can easily run. In Unix/Linux, you cannot run a program unless the execute permission is set. If the execute permission is not set, you might still be able to see/modify the program code(provided read & write permissions are set), but not run it.

    File Permissions in Linux/Unix

    Let’s see file permissions in Linux with examples:

    ls – l on terminal gives

    Here, we have highlighted ‘-rw-rw-r–‘and this weird looking code is the one that tells us about the Unix permissions given to the owner, user group and the world.

    Here, the first ‘‘ implies that we have selected a file.p>

    Else, if it were a directory, d would have been shown.

    The characters are pretty easy to remember.

    r = read permission
    w = write permission
    x = execute permission
    = no permission

    Let us look at it this way.

    The first part of the code is ‘rw-‘. This suggests that the owner ‘Home’ can:

    • Read the file
    • Write or edit the file
    • He cannot execute the file since the execute bit is set to ‘-‘.

    By design, many Linux distributions like Fedora, CentOS, Ubuntu, etc. will add users to a group of the same group name as the user name. Thus, a user ‘tom’ is added to a group named ‘tom’.

    The second part is ‘rw-‘. It for the user group ‘Home’ and group-members can:

    • Read the file
    • Write or edit the file

    The third part is for the world which means any user. It says ‘r–‘. This means the user can only:

    Changing file/directory permissions with ‘chmod’ command

    Say you do not want your colleague to see your personal images. This can be achieved by changing file permissions.

    We can use the ‘chmod’ command which stands for ‘change mode’. Using the command, we can set permissions (read, write, execute) on a file/directory for the owner, group and the world.

    Syntax:

    There are 2 ways to use the command –

    1. Absolute mode
    2. Symbolic mode

    Absolute(Numeric) Mode

    In this mode, file permissions are not represented as characters but a three-digit octal number.

    The table below gives numbers for all for permissions types.

    Number Permission Type Symbol
    0 No Permission
    1 Execute –x
    2 Write -w-
    3 Execute + Write -wx
    4 Read r–
    5 Read + Execute r-x
    6 Read +Write rw-
    7 Read + Write +Execute rwx

    Let’s see the chmod permissions command in action.

    In the above-given terminal window, we have changed the permissions of the file ‘sample to ‘764’.

    ‘764’ absolute code says the following:

    • Owner can read, write and execute
    • Usergroup can read and write
    • World can only read

    This is shown as ‘-rwxrw-r–

    This is how you can change user permissions in Linux on file by assigning an absolute number.

    Symbolic Mode

    In the Absolute mode, you change permissions for all 3 owners. In the symbolic mode, you can modify permissions of a specific owner. It makes use of mathematical symbols to modify the Unix file permissions.

    Adds a permission to a file or directory

    Removes the permission

    Sets the permission and overrides the permissions set earlier.

    Источник

    File permissions and attributes

    File systems use permissions and attributes to regulate the level of interaction that system processes can have with files and directories.

    Contents

    Viewing permissions

    Use the ls command’s -l option to view the permissions (or file mode) set for the contents of a directory, for example:

    The first column is what we must focus on. Taking an example value of drwxrwxrwx+ , the meaning of each character is explained in the following tables:

    Operator Description
    d rwx rwx rwx +
    The file type, technically not part of its permissions. See info ls -n «What information is listed» for an explanation of the possible values. The permissions that the owner has over the file, explained below. The permissions that the group has over the file, explained below. The permissions that all the other users have over the file, explained below. A single character that specifies whether an alternate access method applies to the file. When this character is a space, there is no alternate access method. A . character indicates a file with a security context, but no other alternate access method. A file with any other combination of alternate access methods is marked with a + character, for example in the case of Access Control Lists.

    Each of the three permission triads ( rwx in the example above) can be made up of the following characters:

    Character Effect on files Effect on directories
    Read permission (first character) The file cannot be read. The directory’s contents cannot be shown.
    r The file can be read. The directory’s contents can be shown.
    Write permission (second character) The file cannot be modified. The directory’s contents cannot be modified.
    w The file can be modified. The directory’s contents can be modified (create new files or folders; rename or delete existing files or folders); requires the execute permission to be also set, otherwise this permission has no effect.
    Execute permission (third character) The file cannot be executed. The directory cannot be accessed with cd.
    x The file can be executed. The directory can be accessed with cd; this is the only permission bit that in practice can be considered to be «inherited» from the ancestor directories, in fact if any folder in the path does not have the x bit set, the final file or folder cannot be accessed either, regardless of its permissions; see path_resolution(7) for more information.
    s The setuid bit when found in the user triad; the setgid bit when found in the group triad; it is not found in the others triad; it also implies that x is set.
    S Same as s , but x is not set; rare on regular files, and useless on folders.
    t The sticky bit; it can only be found in the others triad; it also implies that x is set.
    T Same as t , but x is not set; rare on regular files, and useless on folders.

    See info Coreutils -n «Mode Structure» and chmod(1) for more details.

    Examples

    Let us see some examples to clarify:

    Archie has full access to the Documents directory. He can list, create files and rename, delete any file in Documents, regardless of file permissions. His ability to access a file depends on the file’s permission.

    Archie has full access except he can not create, rename, delete any file. He can list the files and (if file’s permission empowers) may access an existing file in Documents.

    Archie can not do ‘ls’ in Documents but if he knows the name of an existing file then he may list, rename, delete or (if file’s permission empowers him) access it. Also, he is able to create new files.

    Archie is only capable of (if file’s permission empowers him) access those files in Documents which he knows of. He can not list already existing files or create, rename, delete any of them.

    You should keep in mind that we elaborate on directory permissions and it has nothing to do with the individual file permissions. When you create a new file it is the directory that changes. That is why you need write permission to the directory.

    Let us look at another example, this time of a file, not a directory:

    Here we can see the first letter is not d but — . So we know it is a file, not a directory. Next the owner’s permissions are rw- so the owner has the ability to read and write but not execute. This may seem odd that the owner does not have all three permissions, but the x permission is not needed as it is a text/data file, to be read by a text editor such as Gedit, EMACS, or software like R, and not an executable in its own right (if it contained something like python programming code then it very well could be). The group’s permissions are set to r— , so the group has the ability to read the file but not write/edit it in any way — it is essentially like setting something to read-only. We can see that the same permissions apply to everyone else as well.

    Changing permissions

    chmod is a command in Linux and other Unix-like operating systems that allows to change the permissions (or access mode) of a file or directory.

    Text method

    To change the permissions — or access mode — of a file, use the chmod command in a terminal. Below is the command’s general structure:

    Where who is any from a range of letters, each signifying who is being given the permission. They are as follows:

    • u : the user that owns the file.
    • g : the user group that the file belongs to.
    • o : the other users, i.e. everyone else.
    • a : all of the above; use this instead of typing ugo .

    The permissions are the same as discussed in #Viewing permissions ( r , w and x ).

    Now have a look at some examples using this command. Suppose you became very protective of the Documents directory and wanted to deny everybody but yourself, permissions to read, write, and execute (or in this case search/look) in it:

    Before: drwxr-xr-x 6 archie users 4096 Jul 5 17:37 Documents

    After: drwx—— 6 archie users 4096 Jul 6 17:32 Documents

    Here, because you want to deny permissions, you do not put any letters after the = where permissions would be entered. Now you can see that only the owner’s permissions are rwx and all other permissions are — .

    This can be reverted with:

    Before: drwx—— 6 archie users 4096 Jul 6 17:32 Documents

    After: drwxr-xr-x 6 archie users 4096 Jul 6 17:32 Documents

    In the next example, you want to grant read and execute permissions to the group, and other users, so you put the letters for the permissions ( r and x ) after the = , with no spaces.

    You can simplify this to put more than one who letter in the same command, e.g:

    Now let us consider a second example, suppose you want to change a foobar file so that you have read and write permissions, and fellow users in the group users who may be colleagues working on foobar , can also read and write to it, but other users can only read it:

    Before: -rw-r—r— 1 archie users 5120 Jun 27 08:28 foobar

    After: -rw-rw-r— 1 archie users 5120 Jun 27 08:28 foobar

    This is exactly like the first example, but with a file, not a directory, and you grant write permission (just so as to give an example of granting every permission).

    Text method shortcuts

    The chmod command lets add and subtract permissions from an existing set using + or — instead of = . This is different from the above commands, which essentially re-write the permissions (e.g. to change a permission from r— to rw- , you still need to include r as well as w after the = in the chmod command invocation. If you missed out r , it would take away the r permission as they are being re-written with the = . Using + and — avoids this by adding or taking away from the current set of permissions).

    Let us try this + and — method with the previous example of adding write permissions to the group:

    Before: -rw-r—r— 1 archie users 5120 Jun 27 08:28 foobar

    After: -rw-rw-r— 1 archie users 5120 Jun 27 08:28 foobar

    Another example, denying write permissions to all (a):

    Before: -rw-rw-r— 1 archie users 5120 Jun 27 08:28 foobar

    After: -r—r—r— 1 archie users 5120 Jun 27 08:28 foobar

    A different shortcut is the special X mode: this is not an actual file mode, but it is often used in conjunction with the -R option to set the executable bit only for directories, and leave it unchanged for regular files, for example:

    Copying permissions

    It is possible to tell chmod to copy the permissions from one class, say the owner, and give those same permissions to group or even all. To do this, instead of putting r , w , or x after the = , put another who letter. e.g:

    Before: -rw-r—r— 1 archie users 5120 Jun 27 08:28 foobar

    After: -rw-rw-r— 1 archie users 5120 Jun 27 08:28 foobar

    This command essentially translates to «change the permissions of group ( g= ), to be the same as the owning user ( =u ). Note that you cannot copy a set of permissions as well as grant new ones e.g.:

    In that case chmod throw an error.

    Numeric method

    chmod can also set permissions using numbers.

    Using numbers is another method which allows you to edit the permissions for all three owner, group, and others at the same time, as well as the setuid, setgid, and sticky bits. This basic structure of the code is this:

    Where xxx is a 3-digit number where each digit can be anything from 0 to 7. The first digit applies to permissions for owner, the second digit applies to permissions for group, and the third digit applies to permissions for all others.

    In this number notation, the values r , w , and x have their own number value:

    To come up with a 3-digit number you need to consider what permissions you want owner, group, and all others to have, and then total their values up. For example, if you want to grant the owner of a directory read write and execution permissions, and you want group and everyone else to have just read and execute permissions, you would come up with the numerical values like so:

    This is the equivalent of using the following:

    To view the existing permissions of a file or directory in numeric form, use the stat(1) command:

    Where the %a option specifies output in numeric form.

    Most folders and directories are set to 755 to allow reading, writing and execution to the owner, but deny writing to everyone else, and files are normally 644 to allow reading and writing for the owner but just reading for everyone else; refer to the last note on the lack of x permissions with non executable files: it is the same thing here.

    To see this in action with examples consider the previous example that has been used but with this numerical method applied instead:

    Before: -rw-r—r— 1 archie users 5120 Jun 27 08:28 foobar

    After: -rw-rw-r— 1 archie users 5120 Jun 27 08:28 foobar

    If this were an executable the number would be 774 if you wanted to grant executable permission to the owner and group. Alternatively if you wanted everyone to only have read permission the number would be 444 . Treating r as 4, w as 2, and x as 1 is probably the easiest way to work out the numerical values for using chmod xxx filename , but there is also a binary method, where each permission has a binary number, and then that is in turn converted to a number. It is a bit more convoluted, but here included for completeness.

    Consider this permission set:

    If you put a 1 under each permission granted, and a 0 for every one not granted, the result would be something like this:

    You can then convert these binary numbers:

    The value of the above would therefore be 775.

    Consider we wanted to remove the writable permission from group:

    The value would therefore be 755 and you would use chmod 755 filename to remove the writable permission. You will notice you get the same three digit number no matter which method you use. Whether you use text or numbers will depend on personal preference and typing speed. When you want to restore a directory or file to default permissions e.g. read and write (and execute) permission to the owner but deny write permission to everyone else, it may be faster to use chmod 755/644 filename . However if you are changing the permissions to something out of the norm, it may be simpler and quicker to use the text method as opposed to trying to convert it to numbers, which may lead to a mistake. It could be argued that there is not any real significant difference in the speed of either method for a user that only needs to use chmod on occasion.

    You can also use the numeric method to set the setuid , setgid , and sticky bits by using four digits.

    For example, chmod 2777 filename will set read/write/executable bits for everyone and also enable the setgid bit.

    Bulk chmod

    Generally directories and files should not have the same permissions. If it is necessary to bulk modify a directory tree, use find to selectively modify one or the other.

    To chmod only directories to 755:

    To chmod only files to 644:

    Changing ownership

    chown changes the owner of a file or directory, which is quicker and easier than altering the permissions in some cases.

    Consider the following example, making a new partition with GParted for backup data. Gparted does this all as root so everything belongs to root by default. This is all well and good but when it comes to writing data to the mounted partition, permission is denied for regular users.

    As you can see the device in /dev is owned by root, as is the mount location ( /media/Backup ). To change the owner of the mount location one can do the following:

    Before: drwxr-xr-x 5 root root 4096 Jul 6 16:01 Backup

    After: drwxr-xr-x 5 archie root 4096 Jul 6 16:01 Backup

    Now the partition can have data written to it by the new owner, archie, without altering the permissions (as the owner triad already had rwx permissions).

    Access Control Lists

    Access Control Lists provides an additional, more flexible permission mechanism for file systems by allowing to set permissions for any user or group to any file.

    Umask

    The umask utility is used to control the file-creation mode mask, which determines the initial value of file permission bits for newly created files.

    File attributes

    Apart from the file mode bits that control user and group read, write and execute permissions, several file systems support file attributes that enable further customization of allowable file operations. This section describes some of these attributes and how to work with them.

    chattr and lsattr

    For ext2 and ext3 file systems, the e2fsprogs package contains the programs lsattr and chattr that list and change a file’s attributes, respectively. Though some are not honored by all file systems, the available attributes are:

    • a : append only
    • c : compressed
    • d : no dump
    • e : extent format
    • i : immutable
    • j : data journalling
    • s : secure deletion
    • t : no tail-merging
    • u : undeletable
    • A : no atime updates
    • C : no copy on write
    • D : synchronous directory updates
    • S : synchronous updates
    • T : top of directory hierarchy

    For example, if you want to set the immutable bit on some file, use the following command:

    To remove an attribute on a file just change + to — .

    Extended attributes

    From xattr(7) : «Extended attributes are name:value pairs associated permanently with files and directories». There are four extended attribute classes: security, system, trusted and user.

    Extended attributes are also used to set Capabilities.

    User extended attributes

    User extended attributes can be used to store arbitrary information about a file. To create one:

    Use getfattr to display extended attributes:

    Finally, to remove an extended attribute:

    Preserving extended attributes

    Command Required flag
    cp —preserve=mode,ownership,timestamps,xattr
    mv preserves by default 1
    tar —xattrs for creation and —xattrs-include=’*’ for extraction
    bsdtar -p for extraction
    rsync —xattrs
    1. mv silently discards extended attributes when the target file system does not support them.

    To preserve extended attributes with text editors you need to configure them to truncate files on saving instead of using rename(2) .[1]

    Tips and tricks

    Preserve root

    Use the —preserve-root flag to prevent chmod from acting recursively on / . This can, for example, prevent one from removing the executable bit systemwide and thus breaking the system. To use this flag every time, set it within an alias. See also [2].

    Источник

    Читайте также:  Установка файла hosts windows
    Оцените статью