failed to execute /bin/bash: Resource temporarily unavailable(Linux系统root无法通过su切换到某个普通用户)

这篇博客记录了在Linux环境下遇到su命令执行失败的情况,错误信息为'资源暂时不可用'。博主首先检查了/etc/security/limits.d/20-nproc.conf配置文件,发现软限制设置为4096,然后尝试将该值更改为8192,但问题仍未解决。最后,博主可能在寻找其他系统资源限制或权限问题以修复此错误。

[root@127.0.0.1 config]# su - mform
Last login: Mon Apr 16 14:08:05 CST 2018 on pts/4
su: failed to execute /bin/bash: Resource temporarily unavailable
[root@127.0.0.1 config]#
[root@127.0.0.1 config]#
[root@127.0.0.1 config]# egrep -v “$|#” /etc/security/limits.d/20-nproc.conf

  •      soft    nproc     4096
    

root soft nproc unlimited
[root@127.0.0.1 config]# su - mform
Last login: Mon Apr 16 14:16:25 CST 2018 on pts/4
su: failed to execute /bin/bash: Resource temporarily unavailable
[root@127.0.0.1 config]#
[root@127.0.0.1 config]#
[root@127.0.0.1 config]#

#将默认值4096改为8192

[root@127.0.0.1 config]# vim /etc/security/limits.d/20-nproc.conf
[root@127.0.0.1 config]# egrep -v “$|#” /etc/security/limits.d/20-nproc.conf

  •      soft    nproc     8192
    

root soft nproc unlimited
[root@127.0.0.1 config]# su - mform
Last login: Mon Apr 16 14:16:49 CST 2018 on pts/4
[mform@127.0.0.1 ~]$ id
uid=1002(mform) gid=1003(mform) groups=1003(mform)

[root@localhost ~]# sudo yum install -y kubelet-1.23.17-0 kubeadm-1.23.17-0 kubectl-1.23.17-0 --disableexcludes=kubernetes 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" 正在尝试其它镜像。 https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" 正在尝试其它镜像。 https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" 正在尝试其它镜像。 https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" 正在尝试其它镜像。 https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" 正在尝试其它镜像。 https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" 正在尝试其它镜像。 https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#35 - "Encountered end of file" 正在尝试其它镜像。 One of the configured repositories failed (Kubernetes), and yum doesn't have enough cached data to continue. At this point the only safe thing yum can do is fail. There are a few ways to work "fix" this: 1. Contact the upstream for the repository and get them to fix the problem. 2. Reconfigure the baseurl/etc. for the repository, to point to a working upstream. This is most often useful if you are using a newer distribution release than is supported by the repository (and the packages for the previous distribution release still work). 3. Run the command with the repository temporarily disabled yum --disablerepo=kubernetes ... 4. Disable the repository permanently, so yum won't use it by default. Yum will then just ignore the repository until you permanently enable it again or use --enablerepo for temporary usage: yum-config-manager --disable kubernetes or subscription-manager repos --disable=kubernetes 5. Configure the failing repository to be skipped, if it is unavailable. Note that yum will try to contact the repo. when it runs most commands, so will have to try and fail each time (and thus. yum will be be much slower). If it is a very temporary problem though, this is often a nice compromise: yum-config-manager --save --setopt=kubernetes.skip_if_unavailable=true failure: repodata/repomd.xml from kubernetes: [Errno 256] No more mirrors to try. https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to packages.cloud.google.com:443; 拒绝连接" https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml: [Errno 14] curl#35 - "Encountered end of file" [root@localhost ~]# [root@localhost ~]# # 启动 kubelet [root@localhost ~]# sudo systemctl enable kubelet Failed to execute operation: No such file or directory [root@localhost ~]# sudo systemctl start kubelet Failed to start kubelet.service: Unit not found.
07-30
<think>好的,我现在需要帮助用户解决在root用户下执行/bin/bash时出现“Permission denied”的问题。首先,我需要回忆一下相关的系统权限知识以及之前处理类似问题的经验。 根据用户提供的引用内容,比如引用[3]中提到,root用户切换普通用户时遇到了同样的问题,通过修改/usr/sbin和/usr/lib64的权限解决了问题。这可能意味着/bin/bash或其依赖的目录权限有问题。 首先,我应该检查/bin/bash文件的权限是否正确。正常情况下,root用户应该对/bin/bash有执行权限。如果权限被错误地修改过,比如去除了执行权限,那么root用户也无法执行。所以,第一步是检查/bin/bash的权限,使用ls -l /bin/bash命令查看,权限应该是-rwxr-xr-x。如果发现权限不对,需要用chmod +x /bin/bash修复。 接下来,考虑可能的SELinux或AppArmor安全模块的问题。这些安全工具可能会限制进程的执行。用户可以使用getenforce命令查看SELinux的状态,如果是Enforcing模式,可以尝试暂时关闭SELinux(setenforce 0)来测试是否是这个问题导致的。如果是,就需要调整策略或添加规则。 另外,引用[2]中提到了修改/etc/sudoers文件来允许普通用户获得权限,但这里用户是root本身,所以这可能不适用。不过,可能需要检查sudoers文件是否有异常配置,或者是否有其他安全策略限制了root的执行权限。 还有可能是文件系统挂载选项的问题。如果/bin所在的文件系统被挂载为noexec,那么任何用户都无法执行其中的文件。检查/etc/fstab中的挂载选项,确保没有noexec标志。如果有,需要重新挂载并修改选项。 此外,检查/bin/bash的完整性也很重要,比如是否被损坏或替换。可以通过rpm -Vf /bin/bash(对于RPM系统)或dpkg -S /bin/bash(对于Debian系统)来验证文件是否被修改过。 最后,如果所有步骤都检查过但问题依旧,可能需要查看系统日志(如/var/log/messages或journalctl)寻找更详细的错误信息,帮助进一步诊断。 总结可能的解决步骤:检查/bin/bash权限,检查SELinux/AppArmor,检查文件系统挂载选项,验证bash文件完整性,检查系统日志。需要逐步排查这些可能性,找到具体原因并对应解决。</think>### 解决root用户执行/bin/bash时出现"Permission denied"的步骤 #### 1. 检查/bin/bash文件权限 **操作命令**: ```bash ls -l /bin/bash ``` - **正常权限应为**:`-rwxr-xr-x`(权限值755) - **若权限异常**,使用以下命令修复: ```bash chmod 755 /bin/bash ``` 若文件权限被错误配置为不可执行(例如缺少`x`标志),会导致所有用户无法执行该文件[^3]。 --- #### 2. 验证SELinux安全模块状态 **步骤**: 1. 查看SELinux当前模式: ```bash getenforce ``` 2. **若结果为`Enforcing`**,临时关闭SELinux测试: ```bash setenforce 0 ``` 3. 再次尝试执行`su - <用户名>`或`/bin/bash`,若问题解决,需调整SELinux策略: ```bash restorecon -v /bin/bash # 恢复文件安全上下文 ``` 或永久关闭SELinux(需谨慎): ```bash sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config ``` --- #### 3. 检查文件系统挂载选项 **操作**: 1. 查看`/bin`目录所在分区的挂载选项: ```bash mount | grep "/bin" ``` 2. **若挂载参数包含`noexec`**(禁止执行),需修改`/etc/fstab`文件: - 找到对应分区的行,移除`noexec`选项 - 重新挂载分区: ```bash mount -o remount,exec /bin ``` --- #### 4. 验证/bin/bash文件完整性 **适用系统**: - **RPM系(CentOS/RHEL)**: ```bash rpm -Vf /bin/bash ``` - **Debian/Ubuntu**: ```bash dpkg -S /bin/bash && debsums -s /bin/bash ``` 若输出显示文件被篡改,需重新安装bash: ```bash yum reinstall bash # CentOS/RHEL apt install --reinstall bash # Debian/Ubuntu ``` --- #### 5. 检查依赖库目录权限(较少见) **操作**: ```bash chmod go+x /usr/sbin /usr/lib64 # 参考引用[3] ``` 某些情况下,bash依赖的动态库路径(如`/usr/lib64`)或系统工具路径(如`/usr/sbin`)权限错误可能导致间接权限问题[^3]。 --- #### 6. 查看系统日志定位问题 **命令**: ```bash journalctl -xe | grep "bash" # systemd系统 tail -50 /var/log/messages # 非systemd系统 ``` 日志可能包含更具体的错误原因(如安全策略拦截记录)。 --- ### 最终验证 修复后尝试切换用户: ```bash su - <目标用户名> ``` 或直接执行: ```bash /bin/bash -c "echo test" ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

carden_coder

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

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

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

打赏作者

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

抵扣说明:

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

余额充值