fastboot and adb not working with sudo
Asked Answered
M

4

15

I have a very weird issue on my Ubuntu machine when trying to run the fastboot command.

When I run:

fastboot devices

I get

no permissions   fastboot

So I run the command with adminidtrator permissions:

sudo fastboot devices

And then I get the result

sudo: fastboot: command not found

How can this be? I have the directory in my PATH and everything works correctly without sudo.

Metalinguistic answered 19/11, 2014 at 12:59 Comment(2)
chmod +x? 5 more to go...I'm done.Bidle
single udev rule to take care of all adb and fastboot devices at once https://mcmap.net/q/99768/-set-up-device-for-development-no-permissionsGnathic
N
37

Instead of forcing permissions via sudo each time you need to run fastboot, you can permanently fix the issue:

  1. use lsusb to identify your device USB VendorID
  2. configure udev to set proper permissions when your device is plugged in
  3. profit!

As a bonus - it will be fixed for adb too.

For example, in my case (for 'Megafon SP-A20i') :

$ fastboot devices
no permissions  fastboot
$ sudo fastboot devices
[sudo] password for kaa: 
MedfieldA9055F28    fastboot
$ 

Let's fix:

First, we need to identify the device:

a) look for usb bus number (hack: I know the device is Intel-based one)

$ fastboot -l devices
no permissions         fastboot usb:1-1.2
$ lsusb |grep 001 |grep -i intel
Bus 001 Device 044: ID 8087:09ef Intel Corp. 
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
$ 

b) look for other Intel devices:

$ lsusb |grep 8087
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 044: ID 8087:09ef Intel Corp. 
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
$ 

Hubs are not smartphones definetely, so - USB vendorID we need is "8087".

Second, configure udev (you must replace "idVendor" value with yours) :

$ sudo sh -c "echo '# Megafon SP-A20i' >> /etc/udev/rules.d/51-android.rules"
$ sudo sh -c "echo 'SUBSYSTEM==\"usb\", ATTR{idVendor}==\"8087\", MODE=\"0666\", GROUP=\"plugdev\"' >> /etc/udev/rules.d/51-android.rules"
$ sudo service udev restart
udev stop/waiting
udev  start/running, process 1821
$ 

Third, re-plug your device to allow udev to perform it's magic.

Final check:

$ fastboot -l devices
MedfieldA9055F28       fastboot usb:1-1.2
$ adb devices
List of devices attached 

$ fastboot reboot
rebooting...

finished. total time: 0.253s
$ sleep 90
$ adb devices
List of devices attached 
MedfieldA9055F28    device

$ 

Voila!

Nertie answered 24/1, 2015 at 16:59 Comment(1)
Thanks this worked, but the line with "lsusb |grep 001 |grep -i intel" messed me up because i was trying to add a nexus 5x phone which is a google phone. So I omitted the "|grep -i intel" part and used "lsusb | grep 001" only and it gave me a full list that showed my nexus 5x device. 'Bus 001 Device 015: ID 18d1:d00d Google Inc." I then used 18d1 in place of 8087 and it workedJuliajulian
C
10

You can use

sudo $(which fastboot) devices

Calderon answered 19/11, 2014 at 13:8 Comment(3)
Thanks. Worked like a charm. How can I fix this though? To work normally as "sudo fastboot devices"?Ojibwa
Please don't use sudo as an answer. running as root is really bad if it isn't necessary.Uraeus
sudo is an impersonation of root, not root. If they advocated su then I could see your point. sudo is the way almost all commands are run in Linux, not sure what the obsession is with not using it for fastboot..Tendentious
Z
0

maybe the problem is your system version is too old,for example ,my system Version is ubuntu 20.10 but after i do these command it works.
1. sudo apt-get update 2. sudo apt-get upgrade 3. sudo apt-get dist-upgrade 4. sudo apt-get install android-tools-fastboot then reboot fastboot Or reboot your devices. ^ ^

Zante answered 9/3, 2023 at 10:6 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Bondon
L
0

When you launch a command using sudo, it's not using your current user profile paths, but the sudoers secure path.

You can edit the secure paths with the following command:

$ sudo visudo

and add your path here :

Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/your/path/here"
Lure answered 13/3, 2023 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.