How to Switch User Given a UID in Linux

linuxsusudouser-accounts

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

Best 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)