新聞中心
Linux中如何禁止用戶登錄?本篇文章為大家詳細(xì)講解一下Linux下禁止用戶登錄具體方法。

我們擁有十多年網(wǎng)頁設(shè)計(jì)和網(wǎng)站建設(shè)經(jīng)驗(yàn),從網(wǎng)站策劃到網(wǎng)站制作,我們的網(wǎng)頁設(shè)計(jì)師為您提供的解決方案。為企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站建設(shè)、微信開發(fā)、重慶小程序開發(fā)、手機(jī)網(wǎng)站開發(fā)、H5技術(shù)、等業(yè)務(wù)。無論您有什么樣的網(wǎng)站設(shè)計(jì)或者設(shè)計(jì)方案要求,我們都將富于創(chuàng)造性的提供專業(yè)設(shè)計(jì)服務(wù)并滿足您的需求。
創(chuàng)建用戶時(shí)設(shè)置禁止shell登錄
默認(rèn)情況下,創(chuàng)建用戶時(shí),將按照/etc/default/useradd文件中定義的為用戶分配shell。
Linux中附帶了一個(gè)/sbin/nologinshell,當(dāng)用戶嘗試連接時(shí),它會(huì)顯示一條消息“This account is current not available”。這是禁止用戶登錄shell的一種方法。下面是使用方式:
useradd -s /sbin/nologin {username}
下面實(shí)例,創(chuàng)建一個(gè)用戶,shell設(shè)置為/sbin/nologin:
[root@localhost ~]# useradd user01 -s /sbin/nologin
[root@localhost ~]# tail -1 /etc/passwd
user01:x:1000:1000::/home/user01:/sbin/nologin
查看/etc/passwd可以看到user01的shell為/sbin/nologin 給user01用戶設(shè)置密碼,然后ssh登錄測試一下:
[root@localhost ~]# echo '123'|passwd --stdin user01
Changing password for user user01.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# ssh user01@localhost
user01@localhost's password: This account is currently not available. Connection to localhost closed.
輸入密碼之后,提示This account is current not available,然后連接就關(guān)閉了。
為現(xiàn)有用戶時(shí)設(shè)置禁止shell登錄
更改現(xiàn)有用戶的shell,可以使用usermod和chsh兩個(gè)命令來修改:
chsh命令使用語法如下:
chsh -s /sbin/nologin {username}
下面修改user02用戶的shell:
# Centos8默認(rèn)沒有安裝chsh,使用下面命令安裝:
[root@localhost ~]# yum -y install util-linux-user
[root@localhost ~]# chsh -s /sbin/nologin user02
Changing shell for user02.
chsh: Warning: "/sbin/nologin" is not listed in /etc/shells.
Shell changed.
usermod命令使用語法如下:
usermod -s /sbin/nologin {username}
下面修改user03用戶的shell:
[root@localhost ~]# usermod -s /sbin/nologin user03
也可以手動(dòng)修改/etc/passwd文件中的用戶shell。
本文標(biāo)題:Linux中禁止用戶登錄具體方法
標(biāo)題網(wǎng)址:http://m.fisionsoft.com.cn/article/dhjjphp.html


咨詢
建站咨詢
