Установка sticky bit linux

sticky бит

sticky-бит позволяет защитить нужные файлы от удаления другими пользователями, в случаях когда пользователи до установки специального бита имеют право на удаление.

Это дополнительная опция настройки прав доступа к файлам в Linux, sticky даёт возможности и расширяет возможности, которые при настройке уровня доступа представляют утилиты chmod и chown.

sticky бит, запрет удаления файла в Linux системах

Установить бит на файл или каталог можно при помощь chmod

Во втором случае сохранятся существующие атрибуты, в первом — они перезапишутся стандартными 644.

sticky запрещает удаление файла всем кроме его владельца и суперпользователя. Другие пользователи системы, даже если они входят в группу владельца, удалить файл не смогут.

Если бит установить на каталог — аналогичные правила будут распространяться на все его содержимое.

sticky устанавливается владельцем файла, им же снимается. Бит остается до снятия или до удаления файла, для которого он добавлен.

Установленный бит защитит файл в том числе от действий суперпользователя. root не сможет удалить файл, но сможет снять запрещающий это действие бит.

Пример добавления sticky бита

Создаёт тестовый файл, для которого будем выставлять и проверять права доступа.

При создании файл получает стандартные для Linux систем права доступа:

sticky бит

Владелец файла и группа владельца — admin, для владельца и группы есть доступ на чтение файла и на запись в него. Для всех остальных пользователей есть право на чтение файла.

Существующие права характеризуются значением 664 для утилиты chmod:

rw: read (4) + write (2) r: read (4)

Добавляем специальный бит

Читайте также:  Сеть между двумя линуксами

Права позволяют всем из группы пользователя писать в файл или удалять его.

-rw-rw-r-T 1 admin admin 0 Mar 23 16:55 /tmp/test

Переключимся на пользователя root

Затем добавим пользователя backup в группу admin

Теперь став пользователем backup попробуем удалить файл

rm: cannot remove ‘test’: Operation not permitted

От имени суперпользователя удаляем sticky бит

Теперь файл можно будет удалить.

Читайте про suid/suid и наследование процессом прав доступа, а также про добавление пользователей в группу sudo и настройку возможности выполнения команд с правами суперпользователя без запроса пароля.

Источник

What is a sticky Bit and how to set it in Linux?

What is a sticky Bit and how to set it in Linux?

The Linux Juggernaut

Today we will see how to set Sticky Bit in Linux. This is next to SGID in our ongoing File and Folder permissions series in Linux. We already discussed about CHMOD, UMASK, CHOWN, CHGRP, SGID and SUID file and folder permissions etc in our the previous posts. In this post we will see

  • What is Sticky Bit?
  • Why we require Sticky Bit?
  • Where we are going to implement Sticky Bit?
  • How to implement Sticky Bit in Linux?

What is Sticky Bit?

Sticky Bit is mainly used on folders in order to avoid deletion of a folder and it’s content by other users though they having write permissions on the folder contents. If Sticky bit is enabled on a folder, the folder contents are deleted by only owner who created them and the root user. No one else can delete other users data in this folder(Where sticky bit is set). This is a security measure to avoid deletion of critical folders and their content(sub-folders and files), though other users have full permissions.

Learn Sticky Bit with examples:

Example: Create a project(A folder) where people will try to dump files for sharing, but they should not delete the files created by other users.

Читайте также:  Linux mint printer setup

How can I setup Sticky Bit for a Folder?

Sticky Bit can be set in two ways

  1. Symbolic way (t,represents sticky bit)
  2. Numerical/octal way (1, Sticky Bit bit as value 1)

Use chmod command to set Sticky Bit on Folder: /opt/dump/

Symbolic way:

chmod o+t /opt/dump/ or chmod +t /opt/dump/

Let me explain above command, We are setting Sticky Bit(+t) to folder /opt/dump by using chmod command.

Numerical way:

chmod 1757 /opt/dump/

Here in 1757, 1 indicates Sticky Bit set, 7 for full permissions for owner, 5 for read and execute permissions for group, and full permissions for others.

Checking if a folder is set with Sticky Bit or not?

Use ls -l to check if the x in others permissions field is replaced by t or T

For example: /opt/dump/ listing before and after Sticky Bit set

Before Sticky Bit set:

-rwxr-xrwx 1 xyz xyzgroup 148 Dec 22 03:46 /opt/dump/

After Sticky Bit set:

ls -l total 8 -rwxr-xrwt 1 xyz xyzgroup 148 Dec 22 03:46 /opt/dump/

Now sticky bit is set, let us check if user “temp” can delete this folder which is created xyz user.

$ rm -rf /opt/dump rm: cannot remove `/opt/dump': Operation not permitted $ ls -l /opt total 8 drwxrwxrwt 4 xyz xyzgroup 4096 2012-01-01 17:37 dump $

if you observe other user is unable to delete the folder /opt/dump. And now content in this folder such as files and folders can be deleted by their respective owners who created them. No one can delete other users data in this folder though they have full permissions.

Читайте также:  Узнать пароль суперпользователя linux

I am seeing “T” ie Capital s in the file permissions, what’s that?

After setting Sticky Bit to a file/folder, if you see ‘T’ in the file permission area that indicates the file/folder does not have executable permissions for all users on that particular file/folder.

Sticky bit without Executable permissions:

so if you want executable permissions, Apply executable permissions to the file.
chmod o+x /opt/dump/
ls -l
command output:
-rwxr-xrwt 1 xyz xyzgroup 0 Dec 5 11:24 /opt/dump/
Sticky bit with Executable permissions:

you should see a smaller ‘t’ in the executable permission position.

How can I find all the Sticky Bit set files in Linux/Unix.

find / -perm +1000

The above find command will check all the files which is set with Sticky Bit bit(1000).

Can I set Sticky Bit for files?

Yes, but most of the time it’s not required.

How can I remove Sticky Bit bit on a file/folder?

chmod o-t /opt/dump/

Post your thoughts on this.

Surendra Anne

Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.

Latest posts by Surendra Anne (see all)

  • Docker: How to copy files to/from docker container — June 30, 2020
  • Anisble: ERROR! unexpected parameter type in action: Fix — June 29, 2020
  • FREE: JOIN OUR DEVOPS TELEGRAM GROUPS — August 2, 2019
  • Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) — August 27, 2018
  • How to use ohai/chef-shell to get node attributes — July 19, 2018

Источник

Оцените статью
Adblock
detector