编写脚本/root/bin/nologin.sh和login.sh,实现禁止和允许普通用户登录系统。

简介: 编写脚本/root/bin/nologin.sh和login.sh,实现禁止和允许普通用户登录系统。

vim /root/bin/nologin.sh

!/bin/bash

read -p "请输入用户名:" username
A=/bin/bash
B=grep "^$username" /etc/passwd | cut -d: -f7
C=grep "^$username" /etc/passwd| cut -d: -f 3
D=grep "^$username" /etc/passwd

if [ $? -ne 0 ];then
echo "系统无此用户..."

elif [ $C -lt 1000 ];then
echo "$username 不是普通用户,请重新输入..."

elif [ "$B"  ==  "$A" ];then
usermod -s /sbin/nologin $username
echo "禁止$username 登录"
fi

vim /root/bin/login.sh

!/bin/bash

read -p "请输入用户名:" username
A=/sbin/nologin
B=grep "^$username" /etc/passwd | cut -d: -f 7
C=grep "^$username" /etc/passwd | cut -d: -f 3
D=grep "^$username" /etc/passwd

if [ $? -ne 0 ];then
echo "系统无此用户..."

elif [ $C -lt 1000 ];then
echo "$username 用户不是普通用户,请重新输入..."

elif [ "$B" == "$A" ];then
usermod -s /bin/bash $username
echo "允许$username 登录"
fi

目录
相关文章
|
4月前
|
Shell Linux
linux shell脚本判断当前登录用户是否为root
linux shell脚本判断当前登录用户是否为root
52 1
|
9月前
|
Shell
Shell 执行 .sh 文件(配置、介绍文件权限)
Shell 执行 .sh 文件(配置、介绍文件权限)
363 0
|
10月前
|
Shell 开发工具 Perl
写一个脚本/root/bin/sumid.sh,计算/etc/passwd 文件中的第10个用户和第20用户的ID之和
写一个脚本/root/bin/sumid.sh,计算/etc/passwd 文件中的第10个用户和第20用户的ID之和
54 1
|
10月前
|
Shell 开发工具
chmod -rw /tmp/file1,编写脚本/root/bin/per.sh,判 断当前用户对/tmp/fiile1文件 是否不可读且不可写 ?
chmod -rw /tmp/file1,编写脚本/root/bin/per.sh,判 断当前用户对/tmp/fiile1文件 是否不可读且不可写 ?
43 1
Zp
|
Shell
执行.sh文件(shell脚本)的几种方式
执行.sh文件(shell脚本)的几种方式
Zp
1159 0
|
Shell
MAC修改.bashrc/.bash_profile无效,默认的用户配置文件是.zshrc,
MAC修改.bashrc/.bash_profile无效,默认的用户配置文件是.zshrc,
213 0
|
Shell
SHELL使用sudo echo x >>时提示权限不够,怎么办?
SHELL使用sudo echo x >>时提示权限不够,怎么办?
224 0
crsstat_lhr.sh脚本内容
crsstat_lhr.sh脚本内容
45 0

热门文章

最新文章