• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Unix /etc/profile confirming existance of home directory

Simple question.  I need to confirm that a home directory exists when a user logs into Solaris and Linux boxes.  If no home, no access.  Ideas?  I was going to use the /etc/profile.  Any examples?
Craig Sharp
Craig Sharp
1 Solution
Here's the example"

# In case $HOME does not exists  exit, otherwise keep going

if [ ! -d "$HOME" ]  ;   then
         echo " $USER home directory does not exists !"
         exit 1
We were trying to do similar when we converted from local accounts to LDAP.  But, be aware not all protocols use /etc/profile

If they (s)ftp into the box for example, it may not run /etc/profile
If they ssh with a command parm  (ssh {hostname} ls)  it may not run /etc/profile

Are you converting to LDAP?

Craig SharpLead Enginneer - Unix Server TeamAuthor Commented:
Perfect, thanks!  I was in brain lock lol.
Craig SharpLead Enginneer - Unix Server TeamAuthor Commented:

I just saw your comments.  Thank you.  Yes we are converting to LDAP, but our only concern based on how our systems are setup is to prevent the developers to login to a command line.
Brian UtterbackPrinciple Software EngineerCommented:
The accepted solution as listed above is not secure, if your intention is to prevent a user from logging into the system if that person does not have a home directory. By the time the shell is executing and the /etc/profile script is being run, the tty stream is set up and accepting data from the controlling terminal. Is the terminal sends an interrupt signal, the execution will be interrupted and the user will be logged in anyway.

On Solaris, the right way to do this is to use a PAM module. Linux supports PAM as well, so it is probably the right thing on Linux as well.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now