- Can we run the same application under different users? Ex: App1 running under both
/home/Usr2/App1on a Linux platform?
- Can we have Same UID for two different users? Ex:
/home/usr2/App2i.e Usr1 and Usr2 having same UID?? If yes then how to do it?
- Can an application switch from one user to another, e.g., app1 running under
/home/usr1can switch to
It's best to post separate questions separately. However, since these can all be answered quickly (and are related), I've done so.
The same application may be run by different users, at different times, or at the same time. The application may run from the same location (so long as both users have access to execute it), or separate copies may be run from different locations (as in your example).
Two different users cannot share a UID. Your UID is actually more central to your user identity (hence the name) than your username. When you own a file or folder, the filesystem contains your UID associated with the file, not your username. Having two users with the same UID would mean having a single user with multiple names (which is also not supported).
Yes, it is possible to switch user identity. You can use
sudo -u other-user command...or (if you are currently
root, or if the target user has login enabled and you know their password)
su other-user -c 'command...'. You can invoke these commands yourself, but scripts and applications can also use them.
See the community documentation,
man sudo, and
man sufor more details on how this works and how to use it. In a program you are writing, you can also use the
man 2 setuidand
man 3 setuid. To run graphical applications, you should use
gksudoor (in Kubuntu)
kdesudoinstead of invoking
sudodirectly (but please note that by default in Ubuntu
su). See this section of the community documentation,
Before writing programs or scripts that change users, I recommend reading up extensively on how user identity works in Unix-like systems.