Linux root用户执行修改密码命令,提示 Permission denied

问题

linux系统中(ubuntu20),root用户下执行passwd命令,提示 passwd: Permission denied ,如下图:
在这里插入图片描述

排查

1.执行 ll /usr/bin/passwd ,查看文件权限是否正确,正常情况是 -rwsr-xr-x. root root,如果不是,请修改至正确权限

2.查看/etc/pam.d/passwd,常见正常内容如下图(centos系统中)
在这里插入图片描述
在另一台ubuntu20机器上查看内容如下:

#
# The PAM configuration file for the Shadow `passwd' service
#

@include common-password

发现此文件内容为 @include common-password
引用了一个common-password文件,此文件在 /etc/pam.d/目录下,然后查看 /etc/pam.d/common-password 文件内容,如下图:

#
# /etc/pam.d/common-password - password-related modules common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of modules that define the services to be
# used to change user passwords.  The default is pam_unix.

# Explanation of pam_unix options:
#
# The "sha512" option enables salted SHA512 passwords.  Without this option,
# the default is Unix crypt.  Prior releases used the option "md5".
#
# The "obscure" option replaces the old `OBSCURE_CHECKS_ENAB' option in
# login.defs.
#
# See the pam_unix manpage for other options.

# As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
# To take advantage of this, it is recommended that you configure any
# local modules either before or after the default block, and use
# pam-auth-update to manage selection of other modules.  See
# pam-auth-update(8) for details.

# here are the per-package modules (the "Primary" block)
password        [success=1 default=ignore]      pam_unix.so obscure sha512
# here's the fallback if no module succeeds
password        requisite                       pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
password        required                        pam_permit.so
# and here are more per-package modules (the "Additional" block)
# end of pam-auth-update config
password        *                               pam_unix.so sha512
password        required                        remember=5

通过对 password 这几行测试,发现将最后两行注释后,即可使用passwd命令

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 这种情况通常是由于文件权限不足导致的。在Linux下,可以使用chmod命令更改文件权限。如果您想给.sh文件添加可执行权限,可以使用以下命令: ``` chmod +x filename.sh ``` 其中,filename.sh是您要执行的.sh文件的名称。在这个命令执行后,您应该能够执行您的.sh文件了。如果您还是无法执行该文件,可能是由于您没有足够的权限执行该文件。您可以使用sudo命令以管理员身份执行该文件。例如: ``` sudo ./filename.sh ``` 这将以管理员身份执行您的.sh文件。 ### 回答2: Linux执行.sh文件出现permission denied的错误提示,是由于当前用户对该.sh文件没有执行权限所导致的。 解决该问题的方法有以下几种: 1. 使用chmod命令修改.sh文件的权限。在终端中执行以下命令: chmod +x 文件名.sh 这将赋予该脚本文件执行权限,然后再次执行该脚本文件即可。 2. 使用sudo执行.sh文件。在终端中执行以下命令: sudo sh 文件名.sh 这将使用超级用户权限来执行.sh文件,需要输入当前用户密码。 3. 使用绝对路径执行.sh文件。在终端中执行以下命令: sh /文件所在路径/文件名.sh 这将直接使用绝对路径来执行.sh文件,无需考虑权限问题。 4. 确保.sh文件所在的目录是挂载的,并且具有执行权限。有时可能是因为.sh文件所在的目录没有正确挂载,导致无法执行.sh文件。 总结而言,对于linux执行.sh文件出现permission denied的问题,主要是由于执行权限不足所致。可以通过修改.sh文件的权限、使用sudo命令、使用绝对路径执行.sh文件或检查目录挂载情况来解决该问题。 ### 回答3: 在Linux系统中,当执行.sh文件时出现"Permission denied"表示没有可执行权限。这是因为在Linux系统中,文件读写和执行权限需要经过相应的设置才能执行。想要解决这个问题,可以采取以下几种方法: 1. 赋予.sh文件可执行权限:使用chmod命令修改文件权限。在终端中输入"chmod +x 文件名.sh",其中文件名是你要运行的.sh文件名。这将给.sh文件赋予可执行权限。 2. 使用绝对路径运行.sh文件:在终端中输入.sh文件的绝对路径,例如"/home/user/file.sh",这将绕过执行权限的问题。 3. 使用sudo命令运行.sh文件:输入"sudo sh 文件名.sh"来执行.sh文件。sudo命令可以使用超级用户(root)权限来运行文件,绕过权限限制。 需要注意的是,使用sudo命令需要输入管理员密码,并且要谨慎使用sudo命令,确保你信任该.sh文件的来源和内容。 总结而言,通过赋予可执行权限、使用绝对路径或者使用sudo命令,你应该能够解决Linux执行.sh文件时的"permission denied"问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jepson2017

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值