I created a new group called tomcat and then created a new user called tomcat that I added to group tomcat:

sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

whoami returns ubuntu

I want to change user from ubuntu to tomcat so I tried su tomcat.

But its asking me for password. I never set a password.

How can I change user to tomcat?


In a typical setup a user without a password will be unable to authenticate, and can't switch to is with just su tomcat, but in your case you are assigning /bin/false as the default shell for that user, so you have to use -s /bin/bash to allowing change to tomcat user.

So if you create a new user you can switch to it using sudo su <username>, but, in your case it won't let you switch to it because of -s /bin/false, and when you do that that mean this user is attempt to used to run daemons.

In regular case use sudo passwd <username> to create a new password for that specific user.

  • I see. Yeah, the tomcat user/group is created to run tomcat as a systemd service. I thought I can become tomcat user when I need to edit files since only the user has read/write permissions. I didn't think I have to set a password using sudo passwd <username>. I think I asked the wrong question. – kimbaudi Dec 21 '16 at 11:46
  • 1
    @kimbaudi to become a tomcat user change the -s /bin/false to -s /bin/bash. then use sudo su tomcat without changing the password – Wissam Roujoulah Dec 21 '16 at 11:47
  • I already created user tomcat. How can I change -s /bin/false to -s /bin/bash? When I run sudo useradd -s /bin/bash -g tomcat -d /opt/tomcat tomcat, I get response useradd: user 'tomcat' already exists – kimbaudi Dec 21 '16 at 11:51
  • @kimbaudi change it from /etc/passwd, file replace the /bin/false with /bin/bash – Wissam Roujoulah Dec 21 '16 at 11:52
  • I just ended up removing user sudo deluser tomcat and then adding user again sudo useradd -g tomcat -d /opt/tomcat tomcat. I didn't have to do -s /bin/bash because that is the default. I can change user as tomcat with sudo su tomcat, but when I try to access a file to edit, I get password prompt. sudo nano conf/tomcat-users.xml returns please enter a password. I still need to sudo passwd tomcat to set the password. Your solution helps me change to tomcat user, but its not what I'm looking for. I think I asked the wrong question. You can update your answer and I will accept it – kimbaudi Dec 21 '16 at 12:05

You have set up your user so that it can't login. OK, this is a good habit to prevent a daemon user such as tomcat, apache, mysal,... from logging in.

Now, your only solution is to switch to that user as root:

sudo su -l -s /bin/bash tomcat

Here, as root (sudo), you are doing a login as user tomcat (su -l tomcat). The -s /bin/<shell> option is necessary since the default shell would be /bin/false, which would end your session immediately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.