Vairetz
Posts: 41
Joined: Wed Apr 27, 2016 4:54 pm

Sudo problem (Raspbian)

Sat Sep 17, 2016 4:05 pm

Hi guys,
I have a very big problem, after I use a chmod command I have a problem with sudo.
Error message is: sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set.
How can I solve it without reinstall raspbian or with reinstall but without lose all program?
Please, anyone could help me? I'm hopeless..
I made a site with a raspi projects' collection, my idea is sharing my projects with other person.
My web site is https://raspiproject.altervista.org/ I hope you like it and you want work with me

User avatar
joan
Posts: 14262
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Sudo problem (Raspbian)

Sat Sep 17, 2016 4:27 pm

We can't tell what else might be wrong.

It will be simplest to reinstall from scratch.

jbudd
Posts: 988
Joined: Mon Dec 16, 2013 10:23 am

Re: Sudo problem (Raspbian)

Sat Sep 17, 2016 4:29 pm

Well the command to set the set uid bit would be chmod u+s /usr/bin/sudo (think so anyway). But it won't let you do that unless you are root or can use sudo.

Can you get a root shell?

Code: Select all

su -
then chmod u+s /usr/bin/sudo

Otherwise maybe mount your sd card in an sd reader on another Linux machine

Vairetz
Posts: 41
Joined: Wed Apr 27, 2016 4:54 pm

Re: Sudo problem (Raspbian)

Sat Sep 17, 2016 4:38 pm

With comand su - ask me the password, I put "raspberry" becouse I have only one user (user: pi password: raspberry) but terminel reply me autentication failed.

I can reinstall OS but I would like to keep all program. If it's only method how can I do?
I made a site with a raspi projects' collection, my idea is sharing my projects with other person.
My web site is https://raspiproject.altervista.org/ I hope you like it and you want work with me

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Sudo problem (Raspbian)

Sat Sep 17, 2016 6:57 pm

If you can get to a root shell by adding init=/bin/bash to /boot/cmdline.txt

Code: Select all

dwc_otg.lpm_enable=0 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
becomes

Code: Select all

dwc_otg.lpm_enable=0 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait init=/bin/bash


You should be able to do that with the NOOBS config editor. Hold [SHIFT] during boot.

If your card has plain Jessie (not NOOBS) insert it in a Windows system and edit cmdline.txt using Notepad++

Boot that and you've got a root shell which you can use to completely destroy your system (if you're not careful) or fix it if you pay attention to what you're doing.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Vairetz
Posts: 41
Joined: Wed Apr 27, 2016 4:54 pm

Re: Sudo problem (Raspbian)

Sun Sep 18, 2016 1:03 am

I try to add to cmdline.txt "init=/bin/bash" but the problem persist :(
I made a site with a raspi projects' collection, my idea is sharing my projects with other person.
My web site is https://raspiproject.altervista.org/ I hope you like it and you want work with me

Vairetz
Posts: 41
Joined: Wed Apr 27, 2016 4:54 pm

Re: Sudo problem (Raspbian)

Sun Sep 18, 2016 6:13 pm

How can I reinstall raspbian without lose my program?
I made a site with a raspi projects' collection, my idea is sharing my projects with other person.
My web site is https://raspiproject.altervista.org/ I hope you like it and you want work with me

DNPNWO
Posts: 126
Joined: Fri Jul 08, 2016 1:51 am

Re: Sudo problem (Raspbian)

Sun Sep 18, 2016 7:02 pm

Vairetz wrote:How can I reinstall raspbian without lose my program?
You don't. Did you not create a backup image or clone?

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Sudo problem (Raspbian)

Sun Sep 18, 2016 7:48 pm

Get a brand new SDCard and a USB reader.

Build a rescue system on the new card. Mount the rubbished card in the reader, mount the reader in the RPi (booted from the rescue system). The GUI will automount the filessystems on there. Collect any valuable data and programs from the rubbished card. Count it as a hard lesson learned.

You can use that old card later as a system backup using the rpi-clone tool.

Always use sudo visudo to edit the /etc/sudoers file. Don't remove the last non-root user unless you can login as root (with PuTTY and a public/private key pair).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
nl3prc
Posts: 160
Joined: Sun Jul 24, 2016 12:39 pm
Location: Den Helder the netherlands

Re: Sudo problem (Raspbian)

Sun Sep 18, 2016 9:35 pm

Is it not an option to use visudo

Code: Select all

visudo paswd root
Then set the root password

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Sudo problem (Raspbian)

Sun Sep 18, 2016 9:37 pm

nl3prc wrote:Is it not an option to use visudo

Code: Select all

visudo paswd root
Then set the root password
visudo is used to edit the sudoers file (nothing more, nothing less). It checks for syntax errors before it saves the file, so you have a chance to avoid a smoking weapon and a large void in your foot.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Vairetz
Posts: 41
Joined: Wed Apr 27, 2016 4:54 pm

Re: Sudo problem (Raspbian)

Sun Sep 18, 2016 11:06 pm

Ok, thank you very much
Now I'm reinstalling Raspbian OS and I promise that I create a backup before launchig inito crazy experiments :D
I made a site with a raspi projects' collection, my idea is sharing my projects with other person.
My web site is https://raspiproject.altervista.org/ I hope you like it and you want work with me

User avatar
nl3prc
Posts: 160
Joined: Sun Jul 24, 2016 12:39 pm
Location: Den Helder the netherlands

Re: Sudo problem (Raspbian)

Mon Sep 19, 2016 7:07 am

Than the best way is to make a new sdcard with rasbian and then put the old card in a card reader and set the chown to root so you can then boot from the old card and use sudo again

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Sudo problem (Raspbian)

Mon Sep 19, 2016 10:18 am

nl3prc wrote:Than the best way is to make a new sdcard with rasbian and then put the old card in a card reader and set the chown to root so you can then boot from the old card and use sudo again
There's an echo in here.
viewtopic.php?p=1039227#p1039227
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
nl3prc
Posts: 160
Joined: Sun Jul 24, 2016 12:39 pm
Location: Den Helder the netherlands

Re: Sudo problem (Raspbian)

Mon Sep 19, 2016 7:46 pm

when the new system hase boot up do sudo passwd root to set the root pasword
enter su -
and than loggin as root with the password you just made

cd into your old system proberly it is in /media/pi/root/usr/bin
and enter chown root:root ./sudo
now you have set it back to root user

ibic
Posts: 3
Joined: Mon Sep 01, 2014 9:41 am

Re: Sudo problem (Raspbian)

Tue Aug 08, 2017 5:50 am

You saved my day :)
Just add a minor point: After adding this parameter, Raspbian will boot with the file system mounted as Read-Only, execute the following command to mount it as Read-Write:

Code: Select all

mount -o remount,rw /
DougieLawson wrote:
Sat Sep 17, 2016 6:57 pm
If you can get to a root shell by adding init=/bin/bash to /boot/cmdline.txt

Code: Select all

dwc_otg.lpm_enable=0 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
becomes

Code: Select all

dwc_otg.lpm_enable=0 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait init=/bin/bash


You should be able to do that with the NOOBS config editor. Hold [SHIFT] during boot.

If your card has plain Jessie (not NOOBS) insert it in a Windows system and edit cmdline.txt using Notepad++

Boot that and you've got a root shell which you can use to completely destroy your system (if you're not careful) or fix it if you pay attention to what you're doing.

User avatar
DougieLawson
Posts: 36123
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Sudo problem (Raspbian)

Tue Aug 08, 2017 8:00 am

There are better things to add to /boot/cmdline.txt for systems running with systemd.

https://freedesktop.org/wiki/Software/s ... Debugging/

Code: Select all

systemd.unit=emergency.target
or

Code: Select all

systemd.unit=rescue.target
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

jahanshahi
Posts: 3
Joined: Mon Dec 31, 2018 9:45 am

Re: Sudo problem (Raspbian)

Mon Dec 31, 2018 11:15 am

Hey guys,
after searching around a multitude number of forums and websites, I found a solution for this issue:

First you must hold the "Shift" key on Raspberry boot to get into NOOBS recovery section of the Raspberry
then you should add the following command at the end of the "cmdline.txt" :

Code: Select all

init=/bin/bash
(do not remove or change any parts of the current commands in cmdline.txt at all)

click on Exit and let the raspberry getting restarted. Then you'll see the root shell but you can't still set a password for "root", because the directory of root config is in Read-only state. so you should firstly use the bellow command to mount and remount the OS Storage to renew write permission:

Code: Select all

mount -o remount,rw /dev/mmcblk0p7/

Code: Select all

mount  /dev/mmcblk0p7/boot
Now you can set a password for the root, using this command:

Code: Select all

sudo passwd root
After setting a password for "root", Restart the raspberry, enter into Recovery mode again and remove the added command (init=/bin/bash) from "cmdline.txt", Exit and restart the Raspberry.

After loading the OS, open the command line and type "SU" to get root access. now enter the password you've set for root user. after getting root access, enter the following commands to restore the corrupt "SUDO" permissions:

Code: Select all

chown -R root:root /usr

Code: Select all

chmod 4755 /usr/bin/sudo
(you can use -R to set permissions recursively for all files and folders).


it's done ;)

Return to “Beginners”