UID详解

UID详解


Linux中的UID、GID、PID

UID

user identifier,用户ID,Linux系统通过UID区分不同用户。

Linux系统中用户(user)分为3类:
+ 普通用户:使用Linux系统的普通真实用户。普通用户能登陆系统,但权限有限,只能在其Home目录(用户目录)、系统临时目录或其他经过授权的目录中操作。UID为500~6000(系统默认普通用户ID从500开始编号)。
+ 系统用户:系统运行时必须有的用户,但并不是真实用户(虚拟用户),不具有登陆系统的能力。UID为1~499.
+ **根用户:**root用户(系统唯一,是真实的,可以登录系统)。root用户拥有最高权限:可以操作任何文件,运行任何命令。UID值为0。

GID

group identifier,组ID,Linux系统通过GID区分不同用户组。

Linux是多用户操作系统。每个用户都至少属于一个组。
用户组(group):就是具有相同特征的用户(user)的集合体。

例如,有时我们要让多个用户具有相同的权限(操作某一文件或执行某个命令),这时就可以把用户都定义到同一用户组。我们通过修改文件或目录的权限,让用户组具有一定的操作权限,这样用户组下的用户对该文件或目录就具有了相同的权限。

用户和用户组的对应关系:
+ 一对一:某个用户可以是某个组的唯一成员
+ 多对一:多个用户可以是同一个组队成员,且不归属其他组
+ 一对多:某个用户可以是多个用户组的成员。
+ 多对多:多个用户对应多个用户组。

PID

process identifier,进程ID,Linux系统通过PID区分不同进程

In computing, the process identifier (normally referred to as the process ID or just PID) is a number to uniquely identify an active process. This number may be used as a parameter in various function calls, allowing processes to be manipulated, such as adjusting the process’s priority or killing it altogether.

程序一运行,系统就会自动分配给进程一个独一无二的PID,进程中止后PID会被系统回收。


Android中的UID、GID、PID

UID

  • Android系统和Linux系统不同:
    • Linux是多用户操作系统,每个用户都具有一个UID(标识用户身份)。
    • Android是单用户操作系统中,每个App都有一个UID(标识应用身份)。
  • Android中, 应用程序在安装时被分配UID,应用程序在设备上的存续期间内,UID保持不变。

GID

  • 一般应用的GID和UID相同

PID

  • 在Android系统中一般不会把已经kill掉的PID重新分配给新的进程,新产生进程的PID一般比之前所有进程的PID都要大。
  • 一个应用只能有一个 UID,但是一个应用中可以有多个进程(PID)。

进程UID分类

Linux中每个进程都拥有:
+ ruid & rgid : 运行进程的真实用户ID、组ID(real user ID),表示的是实际上进程的执行者
+ euid & egid : 有效用户ID、组ID
+ suid & sgid : 保存的用户ID、组ID (注意区分Set User ID (suid))
+ fsuid & fsgid : 用于文件系统访问检查的用户ID、组ID

Real user ID

The real UID (ruid) and real GID (rgid) identify the real owner of the process and affect the permissions for sending signals.

A process without superuser privilege can signal another process only if the sender’s real or effective UID matches the real or saved UID of the receiver. Since child processes inherit the credentials from the parent, they can signal each other.

Effective user ID

The effective UID (euid) of a process is used for most access checks. It is also used as the owner for files created by that process.
The effective GID (egid) of a process also affects access control and may also affect file creation, depending on the semantics of the specific kernel implementation in use and possibly the mount options used.

euid,主要用于校验该进程在执行时所获得的文件访问权限,也就是说当前进程访问文件时检查权限时实际上检查的是该进程的euid。
一般情况下,进程的euid 就是 ruid,但是当要运行的文件设置了setuid 位之后,就会把执行该文件的进程的 euid 临时转变成该文件所有者 UID ,同时进程的suid 变成了此时进程的 euid (即所有者UID)。进程在执行一些与文件访问权限相关的操作时,系统检查的是进程的 euid (即所有者UID) 。

Saved user ID

The saved user ID (suid) is used when a program running with elevated privileges needs to temporarily do some unprivileged work: it changes its effective user ID from a privileged value (typically root) to some unprivileged one, and this triggers a copy of the privileged user ID to the saved user ID slot.

Later, it can set its effective user ID back to the saved user ID to resume its privileges.

suid仅在euid发生改变时保存。

Saved user ID & Set user ID

saved user ID 其实就是 saved set-user-ID,saved user ID 保存的就是进行 set-user-ID 操作之后的值。

Saved user ID 的作用

为什么需要suid?因为当进程没有root权限时,进程在设置euid时会将需要设置的uid和该进程的ruid和suid进行比较。

APUE2 中的解释:
1) If the process has superuser privileges, the setuid function sets the real user ID, effective user ID, and saved set-user-ID to uid.
2) If the process does not have superuser privileges, but uid equals either the real user ID or the saved set-user-ID, setuid sets only the effective user ID to uid. The real user ID and the saved set-user-ID are not changed.
3) If neither of these two conditions is true, errno is set to EPERM, and 1 is returned

也就是说:
1) 当用户具有超级用户权限的时候,setuid 函数设置的id对三者都起效.
2) 否则,仅当该uid为real user ID 或者saved set-user-ID时,setuid 操作只会把 euid 设置为 uid,而 ruid 和 suid(saved set-user-ID) 不会发生改变。
3) 否则,setuid函数调用失败.
也就是说,这个saved set-user-ID更多的作用是在进程切换自己的effective user ID起作用.

APUE2 中的提醒:
Note that we can obtain only the current value of the real user ID and the effective user ID with the functions getuid and
geteuid from Section 8.2. We can’t obtain the current value of the saved set-user-ID.

需要特别提醒的是:并没有任何的API可以获取到进程的saved set-user-ID,它仅仅是系统在调用setuid函数时进行比较而起作用的.

File system user ID

Linux also has a file system user ID (fsuid) which is used explicitly for access control to the file system. It matches the euid unless explicitly set otherwise. Whenever the euid is changed, the change is propagated to the fsuid.

The intent of fsuid is to permit programs(such as the NFS server) to limit themselves to the file system rights of some given uid without giving that uid permission to send them signals. Since kernel 2.0, the existence of fsuid is no longer necessary because Linux adheres to SUSv3 rules for sending signals, but fsuid remains for compatibility reasons.

  • 5
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
GitLab是一个开源的Git仓库管理平台,可以帮助团队协作开发、代码管理和版本控制等。下面是GitLab配置文件的详解。 1. gitlab.rb文件 GitLab的所有配置都在gitlab.rb文件中。这个文件包含了GitLab的所有配置选项,你可以在这里修改GitLab的配置。 2. 邮箱配置 GitLab可以通过邮件发送通知,包括用户注册、密码重置等。要配置邮件,请在gitlab.rb文件中添加以下配置: ``` gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.example.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "[email protected]" gitlab_rails['smtp_password'] = "password" gitlab_rails['smtp_domain'] = "example.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = false ``` 3. SSL/TLS配置 如果你使用SSL/TLS保护GitLab连接,需要在gitlab.rb文件中添加以下配置: ``` nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.crt" nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.key" ``` 4. LDAP配置 如果你使用LDAP进行身份验证,需要在gitlab.rb文件中添加以下配置: ``` gitlab_rails['ldap_enabled'] = true gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' main: # 'main' is the GitLab 'provider ID' of this LDAP server label: 'LDAP' host: '_your_ldap_server' port: 389 uid: 'sAMAccountName' bind_dn: '_the_full_dn_of_the_user_you_will_bind_with' password: '_the_password_of_the_bind_user' encryption: 'plain' # "start_tls" or "simple_tls" or "plain" verify_certificates: true smartcard_auth: false active_directory: true allow_username_or_email_login: false lowercase_usernames: false block_auto_created_users: false base: '_the_dn_of_the_base_where_you_want_to_start_your_search' user_filter: '' EOS ``` 以上是GitLab配置文件的简要介绍,你可以根据需要修改这些配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值