Debian

apt-get 在什麼使用者下安裝軟體?

  • December 23, 2017

我剛剛安裝了一些軟體apt-get,它的所有者和組是“logger”。既然我使用 安裝了軟體sudo,為什麼所有者和組不是“root”?我很確定大約一年前,我pi用新名稱重命名了使用者logger。這可能導致它,如果是這樣,為什麼?

michael@rp3:~ $ ls -l /usr | grep local
drwxrwsr-x  12 root staff  4096 Dec 23 16:49 local
michael@rp3:~ $ ls -l /usr/local
total 32
drwxrwsr-x 2 root staff 4096 Dec 23 16:47 bin
drwxrwsr-x 2 root staff 4096 Apr 10  2017 etc
drwxrwsr-x 2 root staff 4096 Apr 10  2017 games
drwxrwsr-x 2 root staff 4096 Apr 10  2017 include
drwxrwsr-x 4 root staff 4096 Jun  4  2017 lib
lrwxrwxrwx 1 root staff    9 Apr 10  2017 man -> share/man
drwxrwsr-x 2 root staff 4096 Apr 10  2017 sbin
drwxrwsr-x 7 root staff 4096 Dec 23 15:20 share
drwxrwsr-x 2 root staff 4096 Apr 10  2017 src
michael@rp3:~ $ sudo apt-get install test-client
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
 test-utils
The following NEW packages will be installed:
 test-client test-utils
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/1,575 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
WARNING: The following packages cannot be authenticated!
 test-utils test-client
Install these packages without verification? [y/N] y
Selecting previously unselected package test-utils.
(Reading database ... 41030 files and directories currently installed.)
Preparing to unpack .../test-utils_0.1.1-jessie_armhf.deb ...
Unpacking test-utils (0.1.1-jessie) ...
Selecting previously unselected package test-client.
Preparing to unpack .../test-client_0.1.2-jessie_armhf.deb ...
Unpacking test-client (0.1.2-jessie) ...
Setting up test-utils (0.1.1-jessie) ...
Setting up test-client (0.1.2-jessie) ...
michael@rp3:~ $ ls -l /usr/local
total 40
drwxrwxr-x 6 logger logger 4096 Dec 23 16:49 test-client
drwxrwxr-x 3 logger logger 4096 Dec 23 16:49 test-utils
drwxrwsr-x 2 root   staff  4096 Dec 23 16:49 bin
drwxrwsr-x 2 root   staff  4096 Apr 10  2017 etc
drwxrwsr-x 2 root   staff  4096 Apr 10  2017 games
drwxrwsr-x 2 root   staff  4096 Apr 10  2017 include
drwxrwsr-x 4 root   staff  4096 Jun  4  2017 lib
lrwxrwxrwx 1 root   staff     9 Apr 10  2017 man -> share/man
drwxrwsr-x 2 root   staff  4096 Apr 10  2017 sbin
drwxrwsr-x 7 root   staff  4096 Dec 23 15:20 share
drwxrwsr-x 2 root   staff  4096 Apr 10  2017 src

michael@rp3:~ $ cat /etc/passwd | grep 'apt\|logger\|root\|michael'
root:x:0:0:root:/root:/bin/bash
michael:x:1001:1001:,,,:/home/michael:/bin/bash
_apt:x:109:65534::/nonexistent:/bin/false
logger:x:1000:1000:,,,:/home/logger:/bin/bash
michael@rp3:~ $ cat /etc/group | grep 'apt\|logger\|root\|michael'
root:x:0:
michael:x:1001:
wireshark:x:114:michael
logger:x:1000:
michael@rp3:~ $ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
michael  ALL=(ALL:ALL) ALL
anton   ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
michael@rp3:~ $ ls -l /etc/sudoers.d
total 8
-r--r----- 1 root root  27 Oct 18  2016 010_pi-nopasswd
-r--r----- 1 root root 958 Jan 11  2016 README
michael@rp3:~ $ sudo cat /etc/sudoers.d/*
pi ALL=(ALL) NOPASSWD: ALL
#
# As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on
# installation of the package now includes the directive:
#
#       #includedir /etc/sudoers.d
#
# This will cause sudo to read and parse any files in the /etc/sudoers.d
# directory that do not end in '~' or contain a '.' character.
#
# Note that there must be at least one file in the sudoers.d directory (this
# one will do), and all files in this directory should be mode 0440.
#
# Note also, that because sudoers contents can vary widely, no attempt is
# made to add this directive to existing sudoers files on upgrade.  Feel free
# to add the above directive to the end of your /etc/sudoers file to enable
# this functionality for existing installations if you wish!
#
# Finally, please note that using the visudo command is the recommended way
# to update sudoers content, since it protects against many failure modes.
# See the man page for visudo for more information.
#
michael@rp3:~ $

apt-get,或者更確切地說dpkg,使用記錄為擁有包中各種文件的任何使用者來安裝包內容。這通常是root:root,但可以是任何東西;您通常會root:games在遊戲包中看到root:www-data與網路伺服器相關的包中的某些目錄等。(所有權和權限也可以由維護者腳本設置,但這通常不是必需的。)

如果一個包是在 Raspberry Pi 風格的系統上手動創建的,而沒有過多關注所有權(而不是使用fakeroot),那麼完全有可能最終得到一個包含由 擁有的文件的包,並以pi:pi數字標識。在您的系統上,這些最終將屬於logger:logger.

您可以使用 . 查看包中包含的所有權資訊dpkg-deb -c

Debian 軟體包可以在它們的 postinst 腳本中設置文件權限和所有權。

引用自:https://unix.stackexchange.com/questions/412700