一、背景介绍及问题处理

应用报账号不能ssh到主机,首先怀疑是防火墙或hosts.deny限制但查看之下并没有;接着使用其提供的账号密码确实不能登录,怀疑是密码被修改(有个和平时不太一样现像是输入密码后就会提示“Connection to 134.192.232.69 closed by remote host.Connection to 134.192.232.69 closed.”后直接退出,当时没在意现在回头看来是通过验证后主机发现用户资源超出了限制直接强制关闭了连接);其还没回复同意修改密码之前,其反复通过root也不能成功su到用户,提示“su: cannot set user id: Resource temporarily unavailable”,之前已检查过/etc/passwd和/etc/shadow文件用户信息格式正常,文件最后修改日期也已是老早以前,当即判断应该不是用户名密码的问题。

百度“su: cannot set user id: Resource temporarily unavailable”,查看之下大意是说用户资源使用超过了限制,但查看/etc/security/limits.conf和/etc/security/limits.d并没有看到对目标用户的限制,检查用户使用的资源似乎也都不多,判断不出是什么资源出了问题。直接对最常用的文件打开数、进程打开数和堆栈大小在/etc/security/limits.conf末尾追加了对目录用户的限制(之后分析应该是文件打开数问题)(username改为自目标用户):

username    soft    nofile
username hard nofile
username soft nproc
username hard nproc
username soft stack
username hard stack

追回完后保存不用其他操作,从root su和ssh都已正常。

二、资源限制查看的相关命令

ulimit -a    #查看当前用户资源限制
ps -ef |grep username | wc -l #统计用户进程开启数
lsof | grep username | wc -l #统计用户文件打开数

三、limis.conf格式说明

/etc/security/limits.conff配置格式如下:

<domain> <type> <item> <value>

domain代表限制的用户对象,可以是:用户名、@用户组名、*(表示所所有用户的默认配置)、%

type代表限制的资源类型,可以是:

hard--硬限制,受限用户不可自己通过ulimit动态修改此项的值

soft--软限制,用户自己可以自己使用ulimit加资源对应的参数动态修改此项的值(但其范围要在hard限制范围以内不然无效)

- --代表软硬两种限制

说明:所谓动态修改,就是如使徦ulimt -n 10240来将nofile临时修改为10240而不是通过修改limits.conf来修改,当然重启之后配置失效。使用ulimit -a来查看资源限制时有各资源对应的配置选项

item代表限制的具体资源,value代表该资源的限制值:

item 英文全称 中文译名 单位 value(默认值) 备注
core core file size 程序崩溃时产生的内存镜像文件 kb 0(表示不允许生成)  
data data size 数据段大小(?) kb unlimited  
fsize filesize 可打开文件的大小 kb unlimited  
memlock locked-in-memory address space 内存锁(?具体功能不很明白,数据库好像在意这个值) kb 64  
nofile number of open file 可打开文件数 1024  
rss resident set size 常驻内存大小(?) kb   2.4.30版本及以后内核已取消
stack stack size 堆栈段大小 kb 10240  
cpu cpu time 占用cpu时间(?) 分钟 unlimited  
nproc number of processes 可开启的进程数 1024  
as address space 地址空间 kb unlimited  
maxlogins max number of logins 同个用户最大登录数   此项无法限制root用户
maxsyslogins maximum number of all logins on system 系统所有用户登录总数   此项无法限制root用户
priority the priority to run user process with 用户所运行进程的优先级别      
locks locked files 占用文件个数(?) unlimited linux 2.4及之后版本才有
sigpending pending signals 等待信号数 11378 linux 2.6及之后版本才有
msgqueue memory used by POSIX message queues 信息队列 b 819200 linux 2.6及之后版本才有
nice nice priority allowed 谦让度     linux 2.6.12及之后版本才有
rtprio realtime priority 实时优先级(?)     linux 2.6.12及之后版本才有

说明:

1.关于资源限制/etc/security/limits.conf文件本身就有说明,也可查看帮助文件的说明:man limits.conf

2.除了priority和nice,其他项都支持使用-1、unlimited、infinity表示无限制

3.可以看到只有memlock、nofile、stack、nproc、sigpending等几项默认值不是unlimited,所以资源问题一般只关注这几项

4.RHEL6.x版本后引入/etc/security/limits.d/90-nproc.conf用于限制用户打开进程数,与limits.conf的关系是:

5.如果90-nproc.onf与limits.conf存在相同条目的配置那么90-nproc覆盖limits.conf的配置

6.但是如果90-nproc.conf用的是*没有指定用户而limits.conf指定用户那么90-nproc的限制不生效

7.其实90-nproc.conf除了限制nproc其他资源一样可以限制,生效原则与nproc一样

8.其实在/etc/security/limit.d目录下你还可以创建其他任意名字的.conf文件,这些文件中首字母ACSII大的覆盖首字母ASCII小的(首字母一样大的比较第二个字母以此类推)

http://blog.csdn.net/leshami/article/details/38982563

http://blog.csdn.net/taijianyu/article/details/5976319

http://bbs.chinaunix.net/thread-3689299-1-1.html

“su: cannot set user id: Resource temporarily unavailable”处理及limits.conf说明的更多相关文章

  1. su: cannot set user id: Resource temporarily unavailable

    今天R&D所在主机出现su: cannot set user id: Resource temporarily unavailable资源不可用报错,直接通过其他机器ssh huyuh@xxx ...

  2. su: cannot set user id: Resource temporarily unavailable问题解决

    操作环境 SuSE11sp1 问题现象 执行su - test命令切换失败,提示"su: cannot set user id: Resource temporarily unavailab ...

  3. su: cannot set user id: Resource temporarily unavailable【转】

    今天R&D所在主机出现su: cannot set user id: Resource temporarily unavailable资源不可用报错,直接通过其他机器ssh huyuh@xxx ...

  4. su切换用户报错cannot set user id: Resource temporarily unavailable

    su: cannot set user id: 资源暂时不可用   登录root su - tomcat 报错: cannot set user id: Resource temporarily un ...

  5. ssh连接报错Write failed: Broken pipe Resource temporarily unavailable

    问题描述 使用root连接服务器正常,切换普通用户连接报错 具体报错如下:Write failed: Broken pipe 或者:failed to execute /bin/bash: Resou ...

  6. error=11, Resource temporarily unavailable

    问题1:Cannot run program "/bin/ls": error=11, Resource temporarily unavailable 1 15/04/22 14 ...

  7. -bash: fork: retry: Resource temporarily unavailable;centos6.5

    Last login: Wed Jun 18 14:04:11 2014 from 1.1.1.135 -bash: fork: retry: Resource temporarily unavail ...

  8. failed to execute /bin/bash: Resource temporarily unavailable的问题处理

    [admin@localhost ~]$ sudo su - scloanLast login: Tue Jun 12 14:06:31 CST 2018 on pts/3su: failed to ...

  9. -bash: fork: retry: Resource temporarily unavailable

    登陆不了服务器The server refused to start a shell. 登陆服务器后执行ls命令报错:   1 2 $ls -bash: fork: retry: Resource t ...

随机推荐

  1. 踩坑记录:spring boot的POST请求数据注入不了的问题

    概述: 今天在使用spring boot框架的时候,踩了一个坑,是关于control层request body依赖注入的问题的,内容如下: 进过: 由于目前公司采用的系统架构,要求把springboo ...

  2. Mybatis拦截器(一)

    拦截器需要实现 interceptor接口 public interface Interceptor { //3 对目标对象拦截进行处理的内容 Object intercept(Invocation ...

  3. FILE,id不一致

    当图片全部是新增的时候,id和FILE一一对应,后台可以匹配处理. array(1) { ["banner_img"] => array(5) { ["name&q ...

  4. Qt532.【转】Qt在pro中设置运行时库MT、MTd、MD、MDd,只适合VS版本的Qt

    ZC:具体应该设置 什么参数,可以参看 自己转载的文章:"VC.[转]采用_beginthread__beginthreadex函数创建多线程 - CppSkill - 博客园.html&q ...

  5. 《剑指offer》第六十四题(求1+2+…+n)

    // 面试题64:求1+2+…+n // 题目:求1+2+…+n,要求不能使用乘除法.for.while.if.else.switch.case // 等关键字及条件判断语句(A?B:C). #inc ...

  6. 学习笔记48—PS画虚线

    PS画虚线步骤: 1)我们打开PS后,随便新建一个文件. 2)大小随意. 2)我们选择画笔工具,快捷键是B. 3)画笔面板的快捷键是F5. 4)点击画笔预设面板,再点击右边右上角的下三角,在弹出的菜单 ...

  7. Linux下的JDK和OpenJDK有什么具体的区别

      OpenJDK是JDK的开放原始码版本,以GPL(General Public License)协议的形式放出(题主提到的open就是指的开源).在JDK7的时候,OpenJDK已经作为JDK7的 ...

  8. Word Ladder(双向BFS)

    2018-10-02 23:46:38 问题描述: 问题求解: 显然是个解空间遍历问题,每次修改其中一位,由于步长是1,所以可以使用BFS进行解空间的遍历.

  9. Bulk RNA-Seq转录组学习

    与之对应的是single cell RNA-Seq,后面也会有类似文章. 参考:https://github.com/xuzhougeng/Learn-Bioinformatics/ 作业:RNA-s ...

  10. Zabbix安装(debian,centos)

    lnmp和lamp架构搭建一键安装脚本下载地址:https://lnmp.org/download.html  https://github.com/teddysun/lamp/tree/master ...