[CS] Linux Permissions Day-71

cptkuk91·2022년 2월 28일
1

CS

목록 보기
117/139

When user access to files. Permissions are required to Read, Write, or Execute from CLI.

Command to check the owner and permissions of a file

ls -l

Command to change the permissions apply to file

chmod

Check folder or file

When you put ls-l in the Terminal, if it starts with d, it means a directory folder, and if it starts with -, it is a file.

The following r, w, and x indicate read permission, write permission, and execute permission.

user, group, and other

  • user: Owner of the file. By default, the person who created the file becomes the owner.

  • group: A group can contain multiple users. All users belonging to the group have the same access to the file. When you have a project that requires many people to access files, add user is simple way to give permission.

  • other: Other user with access to the file. use special case.


Command to change permission: chmod

chmod command can change permission. There are two ways to change the permission: Symbolic method and Absolute form.

symbolic method

chmod g-r filename # removes read permission from group
chmod g+r filename # adds read permission to group
chmod g-w filename # removes write permission from group
chmod g+w filename # adds write permission to group
chmod g-x filename # removes execute permission from group
chmod g+x filename # adds execute permission to group
chmod o-r filename # removes read permission from other
chmod o+r filename # adds read permission to other
chmod o-w filename # removes write permission from other
chmod o+w filename # adds write permission to other
chmod o-x filename # removes execute permission from other
chmod o+x filename # adds execute permission to other
chmod u+x filename # adds execute permission to user

Absolute form

Absolute form grants authorize through the sum of numbers.
Read(r): 4, Write(w): 2, Execute(x): 1

ex)

chmod 744 helloworld.js
7	4(r) + 2(w) + 1(x)	rwx	read, write and execute
6	4(r) + 2(w) + 0(-)	rw-	read and write
5	4(r) + 0(-) + 1(x)	r-x	read and execute
4	4(r) + 0(-) + 0(-)	r--	read only
3	0(-) + 2(w) + 1(x)	-wx	write and execute
2	0(-) + 2(w) + 0(-)	-w-	write only
1	0(-) + 0(-) + 1(x)	--x	execute only
0	0(-) + 0(-) + 0(-)	---	none

export: environment variable

In Linux, you can check environment variables by simply entering export.

Using environment variables in Javascript

The npm module dotenv allows you to use environment variables in Javascript. It must be installed npm i dotenv module.

npm i dotenv

You can use environment variables through .env.

Create .env file, input environment variables to use, and save.

In order to use the environment variable, you need to import the following command in the place where it will be used.

const dotenv = require("dotenv");
dotenv.config();

You can use environment variables to store and manage sensitive information such as API Key and DB Password.

profile
메일은 매일 확인하고 있습니다. 궁금하신 부분이나 틀린 부분에 대한 지적사항이 있으시다면 언제든 편하게 연락 부탁드려요 :)

0개의 댓글