30

I log into an system as root via ssh.

How do I become the normal user or another user in the command-line?

2

5 Answers 5

39

As root, you may issue

su - username

You will not be prompted for a password.

5

At the command prompt, type:

su -l <normal user>

su is the linux command to Switch User. The -l command line option will open the new terminal session with the user's environment variables. 

1

A secure way is:

$ sudo su - [userid]

Under normal circumstances you might not give just any use sudoer access. Also you don't want to give root remote ssh access. So you would log in under your own userID (or an ID with sudoer access) then execute the command similar to the first answer, but using "sudo".

As mentioned in some of the other commands the "-" will give you the users environment. You will inadvertently be running as that user.

2
  • 1
    If you're using sudo, su doesn't need to be involved. sudo -su <userid> for a normal shell, sudo -iu <userid> for a login shell.
    – muru
    Commented Jun 21, 2015 at 14:28
  • @muru You're right. I didn't want to give a catch 22 and say you can't. I took the question into consideration and gave a safe route to take... Don't log in as root. Look in as a user who has sudo privileges then sudo su - [userid] into that user. Commented Jun 21, 2015 at 16:09
1

penguintutor.com/linux/useradmin-reference

Excerpt:

su (Switch User)

One of the features of Linux is the ability to change userid when logged into a system. This command su is sometimes referred to as superuser , however this is not completely correct. In the early days of UNIX it was only possible to change to the root user, which made for the superuser command however it is now possible to change to any user using the su command. It is more correct to refer to the command as the switch user command.

The switch user command su is used to change between different users on a system, without having to logout. The most common use is to to change to the root user, but it can be used to switch to any user depending upon the users settings. To switch to a different user other than root, then the username is used as the last option on the command.

It is also possible to change to another user by putting the username after the su command. There are two ways of switching users. By putting a '-' after the command will cause the users profile to be read and variables to be set. Without the '-' the previous users settings will still remain.

To use the new users profile and variables

su - username

To continue with the current profile and variables

su username

you can then return to the previous user by entering exit.

3
  • -Always Take the issue of safety first, so the same would be correct to disconnect and return the system to the correct user, the 'su' command will not le give the desired security for the system because you still remain as' Root 'and even security must want to leave this user and return to the correct user. Commented Jun 21, 2015 at 4:07
  • @PauloMaia I don't understand what you mean? Did you read the question? I just want to change from root to normal-user on a system which I have and active terminal session running. This question got alot of down-votes so I found out how to do it and this answers my question. It's simple su lets me change users and your not the first to mention security which I still don't understand the relevance to this. Commented Jun 21, 2015 at 4:12
  • yes! you change from root to another user but to the system you continues like root and this is not secure because the security need be first, with this you think change 'or think changed of the usr but not changed!'. Commented Jun 21, 2015 at 4:23
0

It's su - <username>. However you really want to deny root access via ssh! Refer to /etc/ssh/sshd.conf and the setting PermitRootLogin no.

Not the answer you're looking for? Browse other questions tagged .