How to switch user given a UID?

Vishrant asked:

I only know the UID of a user, is it possible to switch user using UID in CentOS like we do using username like su -u someuser?

My answer:


Look up the username with the id command, e.g.:

id -un 1003

Then put it together with command substitution:

su - $(id -un 1003)

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.