Unix /etc/profile confirming existance of home directory

Posted on 2011-10-10
Last Modified: 2013-12-04
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?
Question by:Craig Sharp
    LVL 38

    Accepted 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
    LVL 6

    Expert Comment

    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?

    LVL 3

    Author Closing Comment

    by:Craig Sharp
    Perfect, thanks!  I was in brain lock lol.
    LVL 3

    Author Comment

    by:Craig Sharp

    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.
    LVL 22

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free camera licenses with purchase of My Cloud NAS

    Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

    Users of Windows 10 Professional can disable automatic reboots using the policy editor. This tool is not included in the Windows home edition. But don't worry! Follow the instructions below to install (a Win7) policy editor on your Windows 10 Home e…
    Our Group Policy work started with Small Business Server in 2000. Microsoft gave us an excellent OU and GPO model in subsequent SBS editions that utilized WMI filters, OU linking, and VBS scripts. These are some of experiences plus our spending a lo…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now