Operating System - HP-UX
1834645 Members
2643 Online
110069 Solutions
New Discussion

Users 'su'-ing to another userid

 
SOLVED
Go to solution
Don Bentz
Regular Advisor

Users 'su'-ing to another userid

I have a group of people who log in with a common userid. I want them to log in as themselves and then "su -" to this common userid, but I'd like to be able somehow to retain their own shell history files? Is this possible?
Insecurity is our friend. It keeps you dependent.
8 REPLIES 8
Pete Randall
Outstanding Contributor
Solution

Re: Users 'su'-ing to another userid

Don,

If you set them up with a script to do the su'ing, yes. Just have the script export HISTFILE=$HOME/`whoami`.hist before the su and make sure that the profile of the common user doesn't reset it. I think that should do it.


Pete

Pete
Robert-Jan Goossens
Honored Contributor

Re: Users 'su'-ing to another userid

Don Bentz
Regular Advisor

Re: Users 'su'-ing to another userid

Excellent, Thanks Pete.
Insecurity is our friend. It keeps you dependent.
Pete Randall
Outstanding Contributor

Re: Users 'su'-ing to another userid

The only complication I can think of is if the login process (invoked by the minus in su -) would cause the HISTFILE to be reset. In that case have the script export HISTORY, then su, then set HISTFILE to the value of HISTORY.


Pete

Pete
Robert Salter
Respected Contributor

Re: Users 'su'-ing to another userid

Working off of Pete's suggestion, you could put this in the common id's .profile

set `who am i`
HISTFILE=$HOME/.history-$1
HISTSIZE=nnn... etc etc

It would create a .history-userid for whoever does "su - " and would their very own.
Time to smoke and joke
Steven E. Protter
Exalted Contributor

Re: Users 'su'-ing to another userid

loguser=$(who am i | awk '{print $1}')

HISTFILE=$HOME/$loguser.history


I like this methodology.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Robert Salter
Respected Contributor

Re: Users 'su'-ing to another userid

If you want to help prod your folks into logging in as themselves and then 'su -'ing create a file with the common userid in it, like /var/adm/.idno

Add the following to your /etc/profile

LOGNAME=`who am i | awk '{print $1}'`
grep $LOGNAME /var/adm/.idno > /dev/null
if [ $? = 0 ]
then
clear
echo "DIRECT LOGIN WITH THIS ID NOT ALLOWED"
echo "Login with your id and then su to $LOGNAME"
exit
fi
Time to smoke and joke
John Dvorchak
Honored Contributor

Re: Users 'su'-ing to another userid

Here is what we do for the root account so we keep our own history file. I put this in the /root/.profile but you can put it in the shared users home directory instead.:

# sets .sh_hist file to id of user

if [ "`tty`" = "/dev/console" ]
then
REAL=console
else
REAL=`logname`
fi


HISTFILE=$HOME/.sh_$REAL
If it has wheels or a skirt, you can't afford it.