Operating System - HP-UX
1833788 Members
2418 Online
110063 Solutions
New Discussion

Re: Could anyone explain it for me ?

 
May_3
Advisor

Could anyone explain it for me ?

Hi,

I login as root and issued the following command:
# su - oracle
$ id
uid=101(oracle) gid=101(dba)
$ who am i
root pts/ta Apr 30 00:01
$ whoami
oracle
$ write oracle
oracle is not logged on.

Could anyone explain the above situation I have encounted?
Thanks!

Best Regards.,
May
May
5 REPLIES 5
Steven Sim Kok Leong
Honored Contributor

Re: Could anyone explain it for me ?

Hi,

The tty is assigned to the login user. When you su, the tty you use still belong to user who login (i.e. root) not the user you su'ed to (i.e. oracle).

This will work:

# su - oracle
$ write root

This will write to pts/ta which is the tty of the login user or root. The message will be shown on your screen even after you su from root to oracle because oracle is using root's tty.

Hope this helps. Regards.

Steven Sim Kok Leong
S.K. Chan
Honored Contributor

Re: Could anyone explain it for me ?

I can duplicate your situation exactly .. for example, say a machine name mars. That machine has no one login to it. So now I telnet to that machine from another mschine (called jupiter) and at the telnet login prompt I logged in directly as root. So now root is the only UID that logged on to it.

mars# who -uR
root ttyp1 Arp28 ... jupiter

Now I switched user to "skchan"

mars# su - skchan
mars# who am i
root
mars# whoami
root
mars# write skchan
skchanis not logged on

This is perfectly normal. The write command only write to the first tty session, in this case it's root, so if you write to "skchan it's not going to work since "skchan" did not directly logged in to mars. Example ..

mars# ps -ef|grep skchan
skchan ttyp1 .. -ksh

Noticed the tty session of "skchan" is the same as that of "root" in the "who -uR" command above ? Write commands looks at "who" is in the "who -uR" output and will only be able to write to the UID in that output.

Now if you open another session in mars by login directly as oracle, write command will work because it sees it in "who -uR".

Hope I'm not confusing you :)

Wodisch
Honored Contributor

Re: Could anyone explain it for me ?

Hello May,

the perhaps simplest explanation is that "who" show who is LOGGED-IN, but "su" does not log-in, but "switch" to the user-id. And as "su" does not enter that piece of information into the "/var/adm/wtmp" (the file read by "who"), "who" cannot know.

HTH,
Wodisch
Trond Haugen
Honored Contributor

Re: Could anyone explain it for me ?

Just to add to Wodisch's explanation. whoami is a different command that 'who am i' (which is who with an option.
As pr the man page whoami will 'print effective current user id' whereas who 'examines the /etc/utmp file to obtain its information'.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Wodisch
Honored Contributor

Re: Could anyone explain it for me ?

And to add to Trond's add-on :-)

use "id" instead - it is shorter and tells you your effective user-id!

Regards,
Wodisch