3 Basic Commands and Simple Shell Scripts Once you have your first Red Hat Enterprise Linux rhel


[root@rhel-instance ]# touch file.txt



Download 1.85 Mb.
View original pdf
Page65/67
Date26.02.2024
Size1.85 Mb.
#63678
1   ...   59   60   61   62   63   64   65   66   67
Pablo Iranzo Gómez, Pedro Ibáñez Requena, Miguel Pérez Colino, Scott McCarty - Red Hat Enterprise Linux 9 Administration-Packt Publishing (2022) -chap 3 82 - 180
[root@rhel-instance
]# touch file.txt

[root@rhel-instance
]# ls -l file.txt

-rw-r--r--. 1 root root 0 Mar 11 22:30 file.txt
As you can seethe file is created with your username as the owner, your main group as the group, and a default set of permissions. The default set of permissions is defined by umask, and in RHEL, the defaults for newly created file permissions areas follows User: Read and write Group: Read Others: Read
To change permissions using chmod, we specify the changes with three characters The first one, which determines whom the change affects u User g Group o Others The second one to add or remove permissions +: Add -: Remove The third one, which determines the permission to be changed r Read w Write x Execute
So, to add write permissions to the group, we can run the following:
[root@rhel-instance
]# chmod g+w file.txt

[root@rhel-instance
]# ls -l file.txt

-rw-rw-r--. 1 root root 0 Mar 11 22:30 file.txt

Checking, reviewing, and modifying file permissions
155
And to remove read permissions from others, we run the following:
[root@rhel-instance
]# chmod or file.txt

[root@rhel-instance
]# ls -l file.txt

-rw-rw----. 1 root root 0 Mar 11 22:30 file.txt
The permissions are stored in four octal digits. This means that special permissions are stored in a number from 0 to 7, the same way user, group, and other permissions are stored, each one of them with a number from 0 to Some examples are shown as follows:
Table 5.2 – Example file permissions
How does it work We assign a number (power of 2) for each permission Read: 2^2 = 4
Write: 2^1 = 2
Execute: 2^0 = 1
Nothing: We add them:
rwx = 4 + 2 + 1 = 7
rw- = 4 + 2 = 6
r-x = 4 + 1 = r- = 4
--- = This is how we can assign permissions using numbers. Now, let’s try it:

Download 1.85 Mb.

Share with your friends:
1   ...   59   60   61   62   63   64   65   66   67




The database is protected by copyright ©ininet.org 2024
send message

    Main page