首页 > 系统相关 >centos(linux):用命令设置用户的shell以及/bin/false和/sbin/nologin的区别

centos(linux):用命令设置用户的shell以及/bin/false和/sbin/nologin的区别

时间:2024-09-25 12:02:52浏览次数:1  
标签:bin sbin git nologin shell Password 1002

一,/bin/false和/sbin/nologin作为shell时的区别

1,/bin/false

/bin/false是一个什么都不做,立即返回非零退出状态的命令。它通常用于禁止用户登录

用户不会收到任何错误或提示信息,登录尝试简单地被拒绝,没有任何解释

2,/sbin/nologin

/sbin/nologin是一个专门设计来阻止用户登录的程序。当被用作用户的登录shell时,它会显示一条拒绝登录的消息(通常是一行文本),然后结束会话

用户将看到一条消息(默认通常是“This account is currently not available.”)。这个消息可以通过编辑/etc/nologin.txt文件来自定义

3, 应用范围:

/bin/false是最严格的禁止login选项,一切服务都不能用,
而/sbin/nologin只是不允许系统login,还可以使用其他ftp等服务

二,用命令设置用户的shell

1,查看用户的shell

直接对/etc/passwd做grep

[root@web git]# grep git /etc/passwd
git:x:1002:1002::/home/git:/bin/bash

也可以用命令:lslogins

[root@web git]# lslogins git
Username:                           git
UID:                                1002
Gecos field:
Home directory:                     /home/git
Shell:                              /bin/bash
No login:                           no
Password is locked:                 no
Password not required (empty):      no
Login by password disabled:         no
Password encryption method:         SHA-512
Primary group:                      git
GID:                                1002
Last login:                         Jul15/16:34
Last terminal:                      pts/0
Last hostname:
Hushed:                             no
Password expiration warn interval:  7
Password changed:                   Jul15/08:00
Maximum change time:                99999
Running processes:                  0

Last logs:
Sep24/14:05 systemd[1570375]: Reached target Shutdown.
Sep24/14:05 systemd[1570375]: Finished Exit the Session.
Sep24/14:05 systemd[1570375]: Reached target Exit the Session.

也可以使用命令getent

[root@web git]# getent passwd git
git:x:1002:1002::/home/git:/bin/bash

2,设置用户shell为nologin

修改指定用户的shell

[root@web git]# usermod -s /sbin/nologin git

查看效果:

[root@web git]# lslogins git
Username:                           git
UID:                                1002
Gecos field:
Home directory:                     /home/git
Shell:                              /sbin/nologin
No login:                           yes
Password is locked:                 no
Password not required (empty):      no
Login by password disabled:         no
Password encryption method:         SHA-512
Primary group:                      git
GID:                                1002
Last login:                         Jul15/16:34
Last terminal:                      pts/0
Last hostname:
Hushed:                             no
Password expiration warn interval:  7
Password changed:                   Jul15/08:00
Maximum change time:                99999
Running processes:                  0

Last logs:
Sep24/14:05 systemd[1570375]: Reached target Shutdown.
Sep24/14:05 systemd[1570375]: Finished Exit the Session.
Sep24/14:05 systemd[1570375]: Reached target Exit the Session.

也可以直接查看passwd

[root@web git]# grep git /etc/passwd
git:x:1002:1002::/home/git:/sbin/nologin

3,设置用户shell也可以用chsh命令

[root@web git]# chsh -s /sbin/nologin git
Changing shell for git.
chsh: Warning: "/sbin/nologin" is not listed in /etc/shells.
Shell changed.

查看效果:

[root@web git]# grep git /etc/passwd
git:x:1002:1002::/home/git:/sbin/nologin

4,当然,直接编辑/etc/passwd也可以,但要注意不要误操作

标签:bin,sbin,git,nologin,shell,Password,1002
From: https://www.cnblogs.com/architectforest/p/18431044

相关文章

  • Linux 启动系统的过程中使用rd.break 在断点前进入shell
    参考:https://man7.org/linux/man-pages/man7/dracut.cmdline.7.html使用rd.break={cmdline|pre-udev|pre-trigger|initqueue|pre-mount|mount|pre-pivot|cleanup}droptoashellbeforethedefinedbreakpointstarts介绍rd.break参数允许您在内核启动过程中......
  • Cannot open self /usr/local/bin/docker-compose or archive /usr/local/bin/docker-
    安装docker-compose时候。出现错误1、在线拉取太费劲。最后使用的离线安装、、参考内容。.github手动下载文件:https://github.com/docker/compose/releases/tag/1.25.0-rc4选择-86版本的内容将文件上传到/usr/local/bin/目录下,重命名为docker-compose,修改文件权限:chmod+x......
  • shell脚本之根据文件修改时间,删除目录下多余的文件
    shell脚本之根据文件修改时间,删除目录下多余的文件需求:目录下至保留5个文件。该需求一般用于备份,这里使用根据文件的修改时间或者创建时间来判断删除,保留最新的5个文件。#!/bin/bash#存放文件的目录addr="/opt/bak"#保留最新文件个数file_save_num=5#目录下文件总数......
  • 如何设置xshell关闭最后一个选项卡标签时不退出软件?
    不知道你是否遇到这个问题,就是在使用xshell的时候,每次关闭最后一个选项卡标签的时候,xshell软件默认就退出了,好多次我都只是想要关闭,而非退出,所以该如何设置,才能到我们的预期的效果呢?解决办法在工具栏中找到,选项打开。然后再高级选项中找到取消最后一个标签关闭时退出xshell的复选......
  • shell编程三
    5.2.3expr使用注意事项:1.使用空格,2.对*号转义.#expr进行计算的时候结果为0,返回值就是1.可以判断返回值大于1即可.或者等于2也行.[root@Kylin-V10-sp3~]#expr1+11+1[root@Kylin-V10-sp3~]#expr1+12[root@Kylin-V10-sp3~]#expr1/11[root@Kylin-V10-s......
  • 【Linux】快速上手shell脚本(适合初学者)
    Shell脚本快速上手什么是Shell脚本?Shell脚本是一种通过命令行界面执行的一系列命令的文本文件,主要用于自动化任务。创建Shell脚本使用文本编辑器(如nano或vim)创建一个以.sh结尾的文件:nanomyscript.sh脚本头部在脚本的第一行指定解释器:#!/bin/bash基本命令ec......
  • Microsoft 365 消息速递:Microsoft 365 PnP Management Shell注册变化
    51CTOBlog地址:https://blog.51cto.com/u_13969817PnPPowerShell和CLIforMicrosoft365是社区提供的开源工具,很多Office365Admin习惯性使用脚本执行一些配置和管理策略的应用,使用名为PnPManagementShell的多租户应用程序注册来授予脚本所需的权限,然而,这个多租户应用程序注册......
  • /bin/bash^M: 错误的解释器: 没有那个文件或目录
    *.sh:行8:$'\r':未找到命令*.sh:行15:未预期的记号"$'{\r'"附近有语法错误*.sh:行15:`start(){ 这个问题通常是由于文件中存在Windows换行符(CRLF)而引起的。在Unix/Linux系统中,脚本应该使用LF换行符,而不是Windows下的CRLF。要解决这个问题,你可以将文件中......
  • 必应bing推广kai户流程教学,满足企业获客需求
    微软Bing广告提供了三种主要广告类型,可以满足大多数出海企业的展示和客户获取需求。搜索广告(SearchAds)包括标准搜索广告和动态搜索广告。当用户的搜索词与投放的关键词匹配时,相应的搜索广告会被触发,向用户展示精准的广告内容。受众广告(AudienceAds)投放后,广告会展示在微......
  • 父子Shell你了解多少?一起解读吧
    一.source和点、bash\sh、./script区别1.source和点,执行脚本,只在当前shell环境中执行生效2.指定bash\sh解释器运行脚本,是开启subshell,开启子shell运行脚本 命令3../script,都会指定shebang,通过解释器运行,也是开启subshell运行命令 二.父Shell的概念pstree|--s......