Linux中怎么禁止用户登录(linux,开发技术)

时间:2024-05-03 05:50:37 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

创建用户时设置禁止shell登录

默认情况下,创建用户时,将按照/etc/default/useradd文件中定义的为用户分配shell。

Linux中附带了一个/sbin/nologinshell,当用户尝试连接时,它会显示一条消息“This account is current not available”。这是禁止用户登录shell的一种方法。下面是使用方式:

useradd-s/sbin/nologin{username}

下面实例,创建一个用户,shell设置为/sbin/nologin

[root@localhost~]#useradduser01-s/sbin/nologin[root@localhost~]#tail-1/etc/passwduser01:x:1000:1000::/home/user01:/sbin/nologin

查看/etc/passwd可以看到user01的shell为/sbin/nologin

Linux中怎么禁止用户登录

给user01用户设置密码,然后ssh登录测试一下:

[root@localhost~]#echo'123'|passwd--stdinuser01Changingpasswordforuseruser01.passwd:allauthenticationtokensupdatedsuccessfully.[root@localhost~]#sshuser01@localhostuser01@localhost'spassword:Thisaccountiscurrentlynotavailable.Connectiontolocalhostclosed.

Linux中怎么禁止用户登录

输入密码之后,提示This account is current not available,然后连接就关闭了。

为现有用户时设置禁止shell登录

更改现有用户的shell,可以使用usermodchsh两个命令来修改:

chsh命令使用语法如下:

chsh-s/sbin/nologin{username}

下面修改user02用户的shell:

#Centos8默认没有安装chsh,使用下面命令安装:[root@localhost~]#yum-yinstallutil-linux-user[root@localhost~]#chsh-s/sbin/nologinuser02Changingshellforuser02.chsh:Warning:"/sbin/nologin"isnotlistedin/etc/shells.Shellchanged.

Linux中怎么禁止用户登录

usermod命令使用语法如下:

usermod-s/sbin/nologin{username}

下面修改user03用户的shell:

[root@localhost~]#usermod-s/sbin/nologinuser03

Linux中怎么禁止用户登录

也可以手动修改/etc/passwd文件中的用户shell。

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:Linux中怎么禁止用户登录的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:怎么使用html5中的canvas标签抠图下一篇:

4 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18