[Ruby] What is permission denied?

2 minute read

Overview

Today I was worried about the permission denied problem while learning automatic deployment, and I felt that I do not have much knowledge of authority system, so I tried to examine it in detail as a review.

Permission means “permission and authority” in English, and denied means “denied in the past tense of denial”. In other words, permission denied has the meaning of “no permission”. And in the programming permission, the information that regulates the authority of “who is allowed to perform what operation” is set. This information is called permissions.

How to check permissions?

Run the ls command with the -l option. Then I think that the screen looks like this.

terminal


$ ls -l
drwxr-xr-x. 20 root root 2077 July 5 14:34 bin/cat

“D” refers to the directory, rwx stands for r (read), w (write), x (execute), and represents “owner”, “group user”, and “other user” from the left. Therefore, it is displayed as “rwxr-xr-x”. *In this case, it is said that the owner has “full permission”, and group users and other users can “read and execute” but not “write”.

How to change permissions?

Specify the chmod command. chmod is read as “change mode”. The format is as follows. chmod <octal number> <file name>

Meaning Number
Read (r) 4
Write (w) 2
Run (x) 1

As an example, you can change the permissions by entering the following command. In this case, the part of chmod 755 file.txt in the second line is relevant.

terminal


$ ls -l file.txt
- rw-r--r-- 1 takuya staff 0 Jul 12 18:58 file.txt

$ chmod 755 file.txt

$ ls -l file.txt
- rwxr-xr-x 1 takuya staff 0 Jul 12 18:58 file.txt*

In other words, “755” is “7(4+2+1)5(4+1)5(4+1)”, and the user has the authority to all, and the group and its user have “Read”. “,” and “execute.”

Super user

A super user is a user who has a strong privilege to perform all kinds of operations. It is also called the “root user” because the user name is root. A super user is a user with strong privileges who is allowed to perform all operations, and can change configuration files and install new applications. It is important that you log in as a general user and operate, and work as a super user only when necessary. There are su command and sudo command as commands, but the difference is that after executing su command, it is necessary to exit from the superuser state with exit command. Also, while the sudo command executes commands on behalf of the root user, the su command allows it to operate on behalf of the root user as it is, so the password of the root user is required. I will.

Tags: ,

Updated: