linux mobile hard disk file can not change the permissions

Original Address: let linux mount mobile hard disk has execute permissions.
This paper attempts to explore the reach make linux system to mount mobile hard disk means to an end of the executable permissions have to sort out the basics of linux system to mount the device, users and groups, as well as document rights aspects.

First, the problem

When the mobile hard disk or U disk into a windows partition format, linux system automatically mount this mobile hard disk to / media directory, view its rights by ls -al, shown as: drwx--, prove that we can enter into the tray when the operator directory, but check the permissions an executable file in the letter, found to be -rw ---, which can read and write to the file, but you can not execute the file, using the chmod change permissions also to no avail, this time on how to obtain permission to execute? (Another example in mobile hard disk on a source code generated by the compiler target program, but when executed by ./, but told no authority, while sudo chmod + x does not play any role, such encounters in practical work when the situation can generally be carried out by linux system disk to copy the source code compiled or compiled object program copied to disk linux systems then use chmod to change the permissions to resolve, but sometimes time-consuming back and forth like a copy, if you can linux system directly mounted removable hard disk has execute permissions on the more convenient)

Two, linux device mount

This question relates to mount the hard drive, you first need to learn about the two systems linux file system and disk mount that / etc / fstab and / etc / mtab, the former is to mount the system partition information, and system boot disk parameters, the file is a static file (after system startup does not change, such as man-made changes, need to reboot the system); which is the current system has a list of mounted disk, the file is a dynamic file, i.e., with the system and mount umount the file system at any time change, such as when insert U disk, system information is written to the disk in the mtab file, when unplug the U disk, the system will delete mtab file information about the disk.

Format fstab file contents are as follows:

/etc/fstab: static file system information.

#

……
proc /proc proc nodev,noexec,nosuid 0 0

……

Mtab file contents format is as follows:

……
proc /proc proc rw,noexec,nosuid,nodev 0 0

……

Visible fstab and mtab file format is the same, it is in accordance with the "Device name - mount point - the partition type - mount option -dump option -pass option" format organized list.

1, the device name is the name of the system devices, such as / dev / sda1 or / etc / sdb1 or / etc / sdc1, these device names can be viewed by sudo fdisk -l command. (Fstab examples above and mtab file format proc device is a virtual device, the disk was not real, but exists only in memory, information is stored about the processes and systems)

2, mount point is to actually mount the disk file created folder, such as ./,./usr, and ./swap such a system default mount point, of course, we can own use mkdir to create a folder as the mount point.

3, the partition type linux below ext2, ext3, ext4, jfs, jfs2, reiserfs, reiser4, swap, etc., FAT and NTFS have other windows below.

4, the common mount options include: (1) auto and noauto: auto allows the system to automatically mount or mounts can mount -a, this option is the default fstab; noauto boot so that the system does not automatically mount or mount - when a mount is not; (2) rw and ro: rw represent read-write access to mount the device, ro denotes read-only access to mount the device; (3) suid and nosuid: suid representation allows the device uid and a gid setting operation, nosuid is allowed to set uid and gid; (4) dev and nodev: dev simultaneously represent special equipment mounted on the file system, nodev mount those showing no special equipment; (5) exc and noexc: exec file execution binary representation allows the file system, noexc course indicates no binary; (6) user, nouser, users and owner: user to allow the user to specify one of ordinary mount the device, nouser ordinary users mount is disabled. the device (only root can mount the device), users allowing all ordinary users to mount the device, owner represents the only owner of the device can be mounted. user and the users option is implicitly noexec, nosuid, nodev option; (7) sync and asnyc: sync indicates / O operations for the I sync device, without buffering, async and sync expressed, buffered; ( 8) defaults: this option is rw, suid, dev, exec, auto, nouser, and async combination of these options. Further, linux system for different file system can also be set to other special options, for example, under the NTFS file system of Windows, may be provided UTF8 (represented in UTF-8 convert the file name), UID = * (designated mount device user id, the id command or can view the / etc / passwd file mode is obtained), GID = * (mount devices specified user group id) and umask =(Permission to mount the device shield, octal value) and so on, FAT under Windows (including msdos, umsdos, vfat, etc.) file system, you can set * = uid , gid = *, the umask = , dmask = (when mounting equipment applied to the catalog of rights mask, octal value) = and the fMask (used in ordinary file permissions when mounting the shield device, octal value). More mount option can be found in man mount.

5, dump option is used to set whether to allow a backup program to back up the file system dump, 0 for no backup, a backup, if the last few days with the dump backup, the backup will be displayed so far.

6, pass option tells fsck program in the boot and in what order to check the file system, 0 means no check on, (./) only 1 partition, other partitions can only be 2, when the same figure would also check.

Three, linux users and groups, and permissions

Understanding of the above are talking about equipment mount, basic already know how to mount mobile hard disk formatted windows partition in linux below, the key is to set mount options to obtain the appropriate permissions. When the user and group permissions directly related concepts, such as the use ls -al command hereinbefore in linux system, information about the permission obtained (10 characters, such as drwx--) can be divided into four portions, i.e., directory / file identifier (the first character, d indicates a directory, - represent files, other can also l, b and c), the owner of the rights (2-4 characters), the owner's user group permissions (first 5-7 characters), and other user rights (the last three characters). Rights play an important role in terms of security linux system, which is not mentioned. Permissions expressed in two ways, i.e., characters and digital: characters as in the above formula with r, w and x each represent three characters to read, write and execute permissions, - denotes not have any access authentication; digital formula representation rights for read, write, and execute permissions, respectively 4,2,1 three digits, 0 does not have any authority, represented by the digital rights to a group of the same needs when the document owner, group and permissions of other users accumulate, such as permissions for a document is - rwx rw- -, it means using a digital 760.

At this point, we can go back and solve the problem, mount the Windows partition format when the file system, we can = uid *, * gid = and = the umask / dmask = / = the fMask * to set permissions, uid and gid of it is not difficult to set up, directly for their own uid and gid can; set permissions mask on the use of digital, the same first number indicates the owner's permission mask, the second number indicates the group permission mask, the first three digits represent other user's permissions mask, if umask = 000, it means that any rights not block any user, that all users have read, write, and execute permissions, another example fmask = 033, it means the owner has read the document, write, and execute permissions, group and other users have read-only access, permissions and shielding 3 (and 1 and 2 of).

Fourth, to solve the problem

In summary, you can add in / etc / fstab the mount configuration like the following, and reboot the system to mount the hard drive to obtain permission to perform.

/dev/sdb1 /media/sdb1 ntfs utf8,uid=1000,gid=1000, umask=000 0 0

Guess you like

Origin blog.csdn.net/wangfenghui132/article/details/78801160