![debian:除 root 之外的所有用户的权限均被拒绝](https://linux22.com/image/1461999/debian%EF%BC%9A%E9%99%A4%20root%20%E4%B9%8B%E5%A4%96%E7%9A%84%E6%89%80%E6%9C%89%E7%94%A8%E6%88%B7%E7%9A%84%E6%9D%83%E9%99%90%E5%9D%87%E8%A2%AB%E6%8B%92%E7%BB%9D.png)
我今天写了一个 bash 脚本,它可能会破坏我的一些用户设置和/或权限。现在我知道在我的实时系统上测试这个脚本是相当愚蠢的 ;)。
什么不起作用?每个以非 root 用户身份运行的进程(postfix、ftp、dovecot 等)。
编辑:文件夹结构因所有者和权限而异。因此,看起来我并没有在根目录级别上进行任何更改。我也无法以新添加的用户身份登录或运行某些内容(请参阅下面的测试)。proftpd 日志显示Unable to open password file /etc/passwd for reading: Permission denied
苏测试
Cannot execute /bin/bash: Permission denied
ls -l
drwxrwxr-x 23 root root 4096 Aug 15 15:26 /
drwxr-xr-x 90 root root 4096 Aug 15 16:38 etc
-rw-rw-r-- 1 root root 1971 Aug 15 16:25 /etc/passwd
-rw-r----- 1 root shadow 2151 Aug 15 16:25 /etc/shadow
drwxrwxr-x 2 root root 4096 Aug 15 16:38 bin
-rwxr-xr-x 1 root root 941252 Sep 25 2014 /bin/bash
剧本
#!/bin/bash
path="/var/www"
if [ $(id -u) -eq 0 ]; then
echo "Enter directory name"
read dirname
pathdir="$path/$dirname"
echo $pathdir
echo "File doesn't exist. Creating now"
mkdir $pathdir
mkdir $pathdir/conf
mkdir $pathdir/docs
mkdir $pathdir/logs
mkdir $pathdir/tmp
mkdir $pathdir/php-fcgi
echo "Folder structure created"
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -d $pathdir -p $pass $username
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
adduser www-data $username
chown root:$user $pathdir
chmod 750 $pathdir
chown $username:$username $pathdir/*
chmod 750 $pathdir/*
confdir=$pathdir/conf
chmod 550 $confdir
cp ./php.ini $confdir
sed -i -e 's#;open_basedir =#open_basedir = '$pathdir'/docs/:'$pathdir'/tmp/#g' $confdir/php.ini
sed -i -e 's#;upload_tmp_dir =#upload_tmp_dir = '$pathdir'/tmp/#g' $confdir/php.ini
sed -i -e 's#;session.save_path =#session.save_path = '$pathdir'/tmp/#g' $confdir/php.ini
chown $username:$username $confdir/php.ini
chmod 440 $confdir/php.ini
generate php-fcgi-starter
cat > $pathdir/php-fcgi/php-fcgi-starter << EOF
#!/bin/sh
PHPRC="${confdir}/"
export PHPRC
export TMPDIR=${pathdir}/tmp
exec /usr/bin/php5-cgi
EOF
chmod 750 $pathdir/php-fcgi/php-fcgi-starter
chattr +i -V $pathdir/php-fcgi/php-fcgi-starter
generate apache vhost
echo "Domain:"
read domain
cat > /etc/apache2/sites-available/$domain << EOF
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName ${domain}
ServerAlias www.${domain}
SuexecUserGroup ${username} ${username}
AddHandler fcgid-script .php
DocumentRoot "${pathdir}/docs"
DirectoryIndex index.htm index.html index.php
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "${pathdir}/docs">
Options Indexes MultiViews FollowSymLinks +ExecCGI
FCGIWrapper ${pathdir}/php-fcgi/php-fcgi-starter .php
Order allow,deny
allow from all
</Directory>
LogLevel warn
CustomLog ${pathdir}/logs/access.log combined
ServerSignature On
</VirtualHost>
EOF
a2ensite $domain
echo "Ready"
else
echo "run as root"
exit 2
fi
答案1
我怀疑你更改了的权限/
。
结果是什么ls -ld /
它应该是这样的
drwxr-x-rx 22 root root 4096 Aug 15 10:29 /
但是也许您使用脚本删除了一些权限(或者甚至更改了所有者)。
chown root:root /
chmod 755 /
应该就能恢复正常了。
答案2
作为初始步骤,尝试对每个用户使用 chown 命令以确保每个用户都具有适当的权限,例如,chown -R [用户] /home/[用户的目录]。
答案3
我很抱歉,我确实在根目录级别更改了权限。大多数 /* 目录都位于750或者-rwxr-x---
如果您遇到类似错误,请检查
ls -ld /
ls -l /
这将导致
drwxr-xr-x
为了
/
/home
/lib
/opt
/var
/mnt
/boot
恢复 / 中的权限标志
chmod 0755 /
chmod 0755 /*
chmod 0777 /tmp
我的灵感来自这里:来源