In this tutorial you will learn how to switch to another user on Ubuntu using the su command.
Code used during this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# Change user ID or become superuser on Ubuntu # Switch user and keep current dir cd /tmp/ su liviu.balan # /tmp pwd # - Provide an environment similar to what the user would expect had the user logged in directly # When - is used, it must be specified as the last su option su - liviu.balan # /home/liviu.balan pwd # -c Specify a command that will be invoked by the shell using its -c # Remains on current user; only execute the -c command su -c "ls -l /var/www/html/" - liviu.balan # Start nemo as root su -c nemo # Defaults to root user sudo su - # Raw su path /bin/su liviu.balan # Auth log: both successful and unsuccessful su are logged tail -f /var/log/auth.log # Print effective userid whoami # man pages man su man whoami Useful links: http://www.linfo.org/su.html |
Useful links:
http://www.linfo.org/su.html