tnrgus
tnrgus

Reputation: 365

How to letting service know the current user name

There is a daemon running as root by upstart in Ubuntu. I have to know the login user name or uid on a daemon.

Although I have searched and tested the command or function like whoami, who am i and geteuid, I have not gotten the result what I want.

Can anybody let me know the solution?

Upvotes: 0

Views: 143

Answers (2)

Arnab Nandy
Arnab Nandy

Reputation: 6712

A small script like this may solve your problem

echo "uid is ${UID}"
echo "username is ${USERNAME}"

Upvotes: 0

tripleee
tripleee

Reputation: 189648

No users are logged in at the time the startup scripts are run.

Typically, daemons are started by root, but sometimes, they use a dedicated user ID either because the software is written that way, or because the startup scripts set them up this way. For example, on Debian-based distros, the web server runs as www-data so that if anybody hacks the web server somehow, they will have very limited access to the system. But how exactly this is configured depends on which daemon and what its startup script and configuration looks like.

If it's your own daemon and you didn't write it or configure it to switch user IDs, it will be running as root.

If your daemon is some sort of server and it needs to know at runtime which client is connecting, (you really need to rephrase your question but) that's mainly a function of how the client connects to the server, not of how the server is started.

Upvotes: 1

Related Questions