More Update

In short, I have to execute a command (sudo nano /etc/passwd) using a Sudoer Account which I know the username and password but I have to login as a non-Sudoer Account

trial #1 su - $USER -s /bin/sh Not Working! since the Sudoer Account doesn't have a shell account (accidentally set to /bin/false)

I have Ubuntu machine with only 2 users: 1. Admin (sudoer) 2. Mysql (non-sudoer)

accidentally changed the admin user on /etc/passwd into /bin/false

now I cannot login as admin, but still can login as mysql as generic user, non-sudo

How could I change back the /etc/passwd?

Is there any way doing this?


I've tried su - $USER -s /bin/sh while login as user POSTGRES but it's not working, since I cannot get into the shell because of /bin/false applied on ADMIN

so sudo is the last hope.. I think..

is anyone know how to execute sudo on ADMIN while we're login as non-sudo user? ex.. login as USER_POSTGRES, and execute a sudo COMMAND as Admin?


1 Answer 1


This makes little sense - you probably have a "root" user as well - although it may not be possible to log in as root.

You can recover your system by rebooting it - and either changing/adding the boot "lernel" line to include "init=/bin/bash" which will give you a root login so you can edit your password file, or by using a recovery disk to do something similar. (See here)

  • Physical altering is not possible at the moment, I am still out of town. I've tried su - user -s /bin/sh with no success, it said "no directory, logging in with HOME=/"... I know my sudo password, is there any way to execute that without su to the user?
    – Ciniose
    Aug 14, 2015 at 9:51
  • Its probably not possible to do what you are trying to to - effectively you are in the position of trying to hack your own server ! There is a command "sudo" which allows you to run a program as another user, but you need to have this set up to allow it - and I'd be extremely surprised if the mysql user is allowed to do this.
    – davidgo
    Aug 14, 2015 at 20:31
  • If you reisssue the command su - admin -s /bin/sh and then run /usr/bin/whoami what is the result ? If that reports "admin" then you should be able to do whatever you need to do (ie su to root and modify /etc/passwd) - you may just need to specify full paths to the commands you use.
    – davidgo
    Aug 14, 2015 at 20:45
  • yes, I'm feeling silly hacking my own server.. I've tried those commands, and return "no directory, logging in with HOME=/" So basically I cannot get into my own account regardless I have the password
    – Ciniose
    Aug 16, 2015 at 12:36
  • Not neccessarily so - it could simply be that your path is incorrect and you are being logged in without a home directory, but, critically - being logged in as admin user which then gives you admin users permissions. Try issue the command again, then go cd /home/admin; ls and see if your files are there.
    – davidgo
    Aug 16, 2015 at 18:18

You must log in to answer this question.

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