`
yaojingguo
  • 浏览: 208194 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Linux File Access Permissions

阅读更多

 

4.5 of Advanced Programming in the UNIX programming has a very clear explanation for file access permissions.

 

Here is an experiment to show the explanation. 

 

 

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, const char *argv[]) 
{
    int fd;

    if ((fd = open("data", O_RDONLY)) < 0) {
        printf("open error\n");
        return 1;
    } else {
        printf("open ok\n");
        return 0;
    }
}
 

 

$ gcc code.c

$ echo abc > data

$ ls -l

 

-rwxr-xr-x 1 jing jing 7174 2010-10-09 17:27 a.out

-rw-r--r-- 1 jing jing  302 2010-10-09 17:19 code.c

-rw-r--r-- 1 jing jing    4 2010-10-09 17:26 data


$ /a.out
open ok

$ chmod u-r data
$ /a.out
open error
$ id
uid=1000(jing) gid=1000(jing) groups=4(adm),20(dialout),24(cdrom),46(plugdev),104(lpadmin),115(admin),120(sambashare),121(vboxusers),125(kvm),126(libvirtd),1000(jing)

Here is the tricky part. If the effective user id is equal to the file owner id and it does not have the read permission, the permission is denied even the effective group id is equal to the file group id and does  has the read permission.

$ sudo chown test data
$ ./a.out
open ok
$ sudo chown :kvm data
$ ./a.out
open ok

kvm is a supplementary group of the current user jing. So the file can be still opened after its group being set to kvm.

$ sudo chmod g-r data
$ ./a.out
open error

$ sudo chown :fax data
$ ./aout
open ok

$ sudo chmod o-r data
$ ./a.out
open error
0
0
分享到:
评论

相关推荐

    Mastering Linux Security and Hardening

    controlling special permissions, encrypting file systems, and much moreMaster the art of securing a Linux environment with this end-to-end practical guideBook Description This book has extensive ...

    Linux for Beginners: An Introduction to the Linux Operating System

    Exactly how permissions work and how to decipher the most cryptic Linux permissions with ease. How to use the nano, vi, and emacs editors. Two methods to search for files and directories. How to ...

    Linux_slides.rar

    Introduction to Linux Module 2 — Logging In and General Orientation Module 3 — Navigating the File System Module 4 — Managing Files Module 5 — File Permissions and Access Module 6 ...

    Linux Administration A Beginner's Guide 5ed.pdf

    - **File System Management:** Understanding file permissions, managing directories, and working with different types of files and storage devices. - **User and Group Management:** Best practices for ...

    Linux系统函数调用大全PDF.rar

    9. **权限和访问控制(permissions and access control)**:`chmod()`, `chown()`, `access()`等函数用于改变文件或目录的权限和所有者,以确保系统安全。 10. **时间与定时器(time and timers)**:`time()`, `...

    linux文件目录权限备份和恢复

    `getfacl`和`setfacl`命令是Linux中用于管理文件和目录访问控制列表(Access Control List, ACL)的工具,它们允许用户超越传统的用户、组和其他权限模型,提供更精细的权限控制。在本文中,我们将详细探讨这两个...

    Windows读写Ext2/Ext3/Ext4文件系统

    It provides Windows NT4.0/2000/XP/2003/Vista/2008 with full access to Linux Ext2 volumes (read access andwrite access). This may be useful if you have installed both Windows and Linux as a dual boot ...

    Wiley.Publishing.Fedora.Linux.Toolbox.1000+.Commands.for.Fedora.CentOS.and.Red.Hat.Power.Users.and.Red.Hat.Power.Users.2008.pdf

    - **File Permissions**: Understanding and modifying file permissions using `chmod` and `chown`. - **Finding Files**: Searching for files based on name, type, size, and other criteria using `find`, `...

    Operating Systems: Three Easy Pieces

    Linux VM ASLR discussion, tiny bit on Meltdown/Spectre, file permissions/access control lists, discussion of TOCTTOU attacks, etc.), more about Linux CFS scheduler, more about Linux VM, changed VMS ...

    LinuxC函数之文件及目录函数.pdf

    printf("File permissions set to owner-read-only\n"); } else { perror("Failed to change file permissions"); } return 0; } ``` 4. `alphasort`函数: `alphasort`是`dirent.h`库中的一个辅助函数,用于...

    第1次Linux作业-终1

    - 文件权限(permissions) - 文件大小(file size) - 最近访问时间(access time) - 最近修改时间(modification time) - 最近改变元数据时间(change time) - 文件的块位置(block pointers),指向文件实际...

    Linux下安装oracle的常见问题小结

    错误提示是"insufficient permissions to access the inventory",这是因为Oracle安装程序在寻找oraInst.loc文件,其中定义了inventory_loc的位置和inst_group。如果之前已安装了11g,oraInst.loc中的设置可能与10g...

    Mastering Ubuntu Server(PACKT,2016)

    The book begins with the concept of user management, group management, as well as file-system permissions. To manage your storage on Ubuntu Server systems, you will learn how to add and format ...

    详解如何备份及恢复 Linux 文件权限

    其中,ACL(Access Control Lists)提供了一种更为精细的权限控制方式,它可以为文件定义额外的权限,不仅限于用户和用户组。在Debian、Ubuntu、Linux Mint等系统中,可以通过`sudo apt-get install acl`安装ACL工具...

    drupal 6.12

    For more information on setting file permissions, see "Modifying Linux, Unix, and Mac file permissions" (http://drupal.org/node/202483) or "Modifying Windows file permissions" ...

    CentOS 7 Server Deployment Cookbook

    You will then learn how to manage users and their permissions, software installs, disks, filesystems, and so on. You'll then see how to secure connection to remotely access a desktop and work with ...

    UNIX环境高级编程(第二版,英文版)

    File Access Permissions Section 4.6. Ownership of New Files and Directories Section 4.7. access Function Section 4.8. umask Function Section 4.9. chmod and fchmod Functions ...

    Ubuntu Pocket Guide and Reference: A concise companion for day-to-day Ubuntu use

    - **Advanced Features**: Advanced features like searching for files, previewing file contents, and managing permissions are explored. **Command-Line Interface (CLI)** - **Basics of Command Line**: ...

    Ubuntu The Complete Reference

    - **Permissions and Ownership**: Detailed explanation of file permissions and ownership, including how to change them using commands like `chmod` and `chown`. #### Part V - Applications **Chapter 13...

Global site tag (gtag.js) - Google Analytics