0

I am new to Linux environment and I need little guidance. I made a mistake while setting up the password and username of mosquito MQTT broker on AWS ubuntu 18.04 instance. I have altered the contents of /etc/passward file. Because of this sudo is completely broken. Whenever I try to give commands related to sudo, I am getting the above mentioned error. Later I found out there is another backup file in /etc/passward- file. So I need to copy the contents of /etc/passward- to /etc/passward in order to restore sudo. I tried using normal cp command but unfortunately I got an error saying "Permission denied". Is there anyway I can copy without using sudo?

NOTE: I am using AWS ubuntu 18.04 linux instance.

Any suggestions are welcomed.

Thank you

  • So after messing up the only user who could issue root commands, (and it's really more complicated, involving the shadow file too), you need root commands to fix the problem -- Boot another instance, with a working sudo, mount the problem system, and fix, or just reinstall. Ask for help on what you are trying to do. – ubfan1 Nov 10 '20 at 17:18
  • I found a solution in website in order to copy the contents, I should into boot into single user mode in order to copy. https://www.thegeekdiary.com/centos-rhel-how-to-recover-from-deleted-etcpasswd-file/ This is the website that Iam speaking about. Could you guide me how to boot into single user mode – chaya kumar Nov 10 '20 at 17:27
  • See https://askubuntu.com/questions/132965/how-do-i-boot-into-single-user-mode-from-grub – ubfan1 Nov 10 '20 at 17:33
  • Where do I find GRUB menu? – chaya kumar Nov 10 '20 at 17:37
  • When you boot, the grub menu is displayed. Type "e" to edit it (instructions are at the bottom), add the single, and ctrl-X to boot – ubfan1 Nov 10 '20 at 17:38
  • Now I am using the ubuntu AWS instance OS through SSH. How do I boot in this case? Generally for booting OS will be in PC in my case the problem is it is not from PC. I am using the OS remotely using SSH – chaya kumar Nov 10 '20 at 17:43
  • 1
    You don't. ANY suggestion about Grub you can forget. There is no grub when using instances. There are 2 methods: ssh. Use sudo -i to get to a #. If that does not work you need to use the AWS CONSOLE from the website and see if you can log directly into root. Otherwise you killed your instance. IF your instance was created using mountable partitions you can create a new instance, mount your broken one. fix it using commands and then try to make it the bootable instance. – Rinzwind Nov 10 '20 at 18:08
  • 1
    ... I would suggest to FIRST from your ssh connection to create a backup of all your personal data and copy it over to your system using your current ssh connection. – Rinzwind Nov 10 '20 at 18:09
  • You should look for the Amazon documentation for AWS booting. https://aws.amazon.com/premiumsupport/knowledge-center/revert-stable-kernel-ec2-reboot/ Maybe easier to start fresh? – ubfan1 Nov 10 '20 at 18:09

1 Answers1

0

Obviously the password file is protected from update. It is almost certain you're going to need root access there.

  1. Try sudo (in this case, it didn't work)

  2. Try signing in with root's password or perhaps using the su command as in

    su root

  3. Something I've not tried, what if you could mount the harddrive using a system booted from say a USB stick. In that instance, you probably have root and sudo access (on the stick) if the operating system is coming from the stick. In that situation, the password file of the harddrive is just a file which the stick's root should be able to modify/replace.

  • Iam not using any hardware over here. It is from AWS instance. I am using operating system through SSH – chaya kumar Nov 10 '20 at 17:33
  • If you don't have physical access to the system and sudo isn't working then item #2 is the only possibility. Consider this from a security point of view. If there was another method to alter system secured files, it would be considered a major vulnerability. – user628388 Nov 13 '20 at 02:27