in my Linux machine - red-hat

I successfully to login to different users as the following

su - userC
[machine@Linux ~]$ pwd
[machine@Linux ~]$ /Users/userC

but only in one user I get the following

su - UserA
Creating directory '/User/UserA'.
could not open session

please advice from where I get the message "could not open session"

what could be the problem ?

  • what is the output of getent passwd and are you using LDAP, flat files, or something else? It really looks like UserA's shell is set to /sbin/nologin – SailorCire Dec 2 '14 at 17:50
  • Does that directory exist? Is the difference in case on /Users/userC and /Users/UserA a typo? Intentional? The problem? – Etan Reisner Dec 2 '14 at 17:51
  • yes I already tried the getent passwd and the output is fine – maihabunash Dec 2 '14 at 17:53
  • if I am using LDAP , not sure but the file /etc/openldap/ldap.conf exist in my machine so I guess yes – maihabunash Dec 2 '14 at 17:59
  • but which file or app send the mesg - could not open session? – maihabunash Dec 2 '14 at 18:03
root@hostname # su - oracle
could not open session

root@hostname # grep oracle.*nofile /etc/security/limits.conf
oracle          -       nofile          unlimited

set nofile in limits.conf to some number instead of unlimited:

root@hostname # vi /etc/security/limits.conf
root@hostname # grep oracle.*nofile /etc/security/limits.conf
oracle          -       nofile          65536
root@hostname # su - oracle
-bash-4.1$ id
uid=201(oracle) gid=5504(oinstall) groups=5504(oinstall),251(dba),5502(asmdba),5505(oper)
| improve this answer | |
  • On my system, the soft OS limit is: cat /proc/sys/fs/file-max # 512000 Which suggests you need the line oracle - nofile 512000 instead – James McGuigan Mar 1 '18 at 13:58

This is what worked for me, in my case su was working for some users. So, I checked the content of /etc/pam.d/su and it had the following two lines :

session include system-auth

session optional pam_xauth.so

I commented out the first one, restarted the session and it worked.

| improve this answer | |
  • This worked for me! – カメハメハ Jul 6 '19 at 9:36
  • This worked, but any idea why this needs to be changed? – Justin Sep 9 '19 at 19:39
  • 1
    ya, this also worked for me. But I'm truly curious about why this is happening. As an additional layer of the problem, this ONLY occured when I had nofile limits set in /etc/security/limits.conf for the user it was effecting -- if I removed EITHER the session include system-auth in pam.d/su OR the nofile limits in /etc/security/limits.conf the Su would start working again. – Mr.Budris Feb 26 at 19:34

If "nofile" is set to "unlimited" in /etc/security/limits.conf (or in files in limits.d) then the user cannot login.

| improve this answer | |

Commenting out 'session include system-auth' worked for me.

env: docker oraclelinux:latest, after installing oracle-database-server-12cR2-preinstall.x86_64 package.

| improve this answer | |

commenting "session required pam_limits.so" in all files in "/etc/pam.d" solves

  • su: cannot open session: Permission denied
  • runuser: cannot open session: Permission denied


sed -i -r 's/^(session\s+required\s+pam_limits.so)/#\1/' /etc/pam.d/*
| improve this answer | |

Some times it happens to me with error "could not open session" and It works with just type

sudo bash
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.