Безопасность Linux

Revision as of 09:31, 18 January 2023 by Krotesk (talk | contribs) (Created page with "Учетная запись root - это учетная запись администратора или суперпользователя. Эта учетная запис...")
Other languages:
English • ‎Türkçe • ‎русский

Обзор

Системная безопасность - это сложная тема, которую люди изучают в течение многих лет. Было бы нецелесообразно передавать даже часть этих знаний в статье Wiki. На этой странице мы попытаемся дать начальный курс по самым основным элементам безопасности Linux и определить общие подводные камни для новичков.


Пользователи

Учетные записи пользователей используются для входа в систему и являются одним из основных строительных блоков для разрешений. Пользователей можно условно разделить на несколько категорий:

  • Учетные записи обычных пользователей, например, созданные для вас во время установки.
  • Учетные записи, используемые для запуска определенных процессов. Эти пользователи обычно называются в честь службы, которую они запускают. Например, пользователи dbus - это пользователи для запуска главного процесса dbus.
  • Учетная запись root.


Учетная запись root - это учетная запись администратора или суперпользователя. Эта учетная запись имеет доступ ко всему в системе и должна использоваться с особой осторожностью. В большинстве случаев ее вообще не следует использовать. Вместо этого используйте sudo.


sudo

The command sudo lets you run a command as the root user without actually switching to the root user. In many cases this is safer than using the root user directly as only a single command is being run as root. For example, your normal user account would not be able the file /etc/fstab because it is owned by root. However, you can edit it with sudo like this:

sudo nano /etc/fstab


When you run this command, you will be asked for a password, this will be the password of your normal user account.
For more information about editing configuration files owned as root see this article on configuration files.


sudo vs su

While sudo and su look similar and both involve root access they are very different. sudo runs a single command as another user and requests the password of your normal user account. su lets you *become* root and requests the password of the root user. In general, it is usually safer to use sudo than to use su.

Warning
Never run a graphical program as root or with sudo, it should only be used with command line programs


Why am I Asked for a Password

Sometimes you will take an action in the terminal or through a GUI application and will get prompted for your password. This is because the action you are trying to take cannot be completed by you user and requires elevated rights. Whenever you get a password prompt like this it is important to pause and think if the action you are taking *should* be asking for elevated rights before entering your password.

Note
Usually these password prompts will be looking for the password of your normal user account but occasionally they will need the password of the root account


Changing Passwords

To change the password of the user account you are logged in as you can use the command:

passwd


To change the password of a different user on the same system you can use sudo:

sudo passwd USERNAME


Groups

Users on a Linux system are commonly arranged in groups. A user group is a convenient way of assigning more users access to a common task like sound, media, printing and mounting of removable drives etc.


A list of the current groups can be seen on the system with the command:

getent group | awk -F : '{print $1}'


To see which groups a given user belongs to use the command

groups USERNAME


Primary Groups

A user can be a member of any number of groups but they have only one primary group. The primary group is the group used when files are created.


File Permissions

At the most basic level, files are designated as read, write or execute to the user(owner), the group and other. To understand how this works let's look at a real world example.

To get the permissions on the file we can use the command ls -l.

ls -l /etc/fstab
-rw-r--r-- 1 root root 539 Dec 26 23:07 /etc/fstab


That first group of letters and dashes indicate the permissions. It is 10 characters long and the dashes indicate a lack of permissions.

  • The first character "-", represents the file type, "-" indicates that it is a normal files.
  • The next three characters "rw-" indicate the permissions for the user or owner of the file. In this case reading and writing are allowed but not executing.
  • The next three characters "rw-" indicate the permissions for members of the group who owns the file. In this case reading and writing are allowed but not executing.
  • The next three characters "r--" indicate the permissions for other users. In this case reading is allowed but not writing or executing.


From more detailed information on how file permissions are broken down take a look at this Wikipedia article


Changing File Permissions

The command chmod can be used to change permissions on a file or directory. It is probably easier to demonstrate than explain.


Add read rights to the user(owner) of the file

chmod u+r filename


Remove execute rights to members of the group owner of filename

chmod g-x filename


Set the rights for the other group to read only

chmod o=r filename


Of course, in normal use you would combine everything like this:

chmod u+rw,g=r,o-rwx filename


This adds read and write to the owner, set the group as read only and remove read, write and execute from other users


The chmod command can do a lot more than that. For more information take a look at Wikipedia's chmod reference


Firewalls

The Firewalls article has a full description of the Firewall solutions available on Manjaro.


File Integrity Monitoring

Your first line of defense should always be security practices that prevent an intrusion such as firewalls, intrusion prevention systems and keeping your system patched and up-to-date. However, it is also useful to try to ensure that your system has not been compromised. One way to help with this is by using a file integrity monitoring solution. These solutions work by comparing the checksums or the files on your system to their previous versions and alerting about changes.

An open source tool which provides this service is AIDE(Advanced Intrusion Detection Environment. You can install it with the command:

pamac install aide


Sandboxing

A Sandbox is a security mechanism for separating running programs, usually in an effort to mitigate system failures or software vulnerabilities from spreading.


One method of sandboxing is using Firejail. Please the Firejail Wiki page for more information on installing and configuring Firejail.