I was looking for hours, maybe more, for a solution and i just found it. I want to share it with everyone. This way it will be easier googling this problem to find the solution faster. So, just like the title says, below is the solution.
4 Answers
In terminal:
grep . /sys/bus/usb/devices/*/power/wakeup
The result, for me, was to find out that all usb were disabled.
So now, type:
sudo su
we have now root privillages.
I have 8 usb ports (you do that for as many usb ports you have) ,so:
echo enabled > /sys/bus/usb/devices/usb1/power/wakeup echo enabled > /sys/bus/usb/devices/usb2/power/wakeup echo enabled > /sys/bus/usb/devices/usb3/power/wakeup echo enabled > /sys/bus/usb/devices/usb4/power/wakeup echo enabled > /sys/bus/usb/devices/usb5/power/wakeup echo enabled > /sys/bus/usb/devices/usb6/power/wakeup echo enabled > /sys/bus/usb/devices/usb7/power/wakeup echo enabled > /sys/bus/usb/devices/usb8/power/wakeup
Go ahead and test it. Now you can wake up from any wireless or wired usb keyboard and mouse.
So then, the reason we must enable all of them, is because in the next step, we will write this in rc.local to execute the command after every reboot, and after reboot some linux distros (maybe all) change the usb ports. We don't have to worry for anything going wrong by enabling all of them, since linux is in suspend or hibernation, it can't use the wifi to download anything, so it won't wake up without we wake it up on purpose.
Run
sudo nano /etc/rc.local
and we paste everything from step 2. in there (before the exit 0 of course).
That's it. From now on we can use our wireless usb and mouse to wake up from suspend.
I hope it works for all of you. This guide was made after testing all other possible solutions around the internet.

- 15,657

- 2,553
In addition to my guide above i want to add this information, because i recently discovered that some wireless usb devices after waking up from sleep, they revert back to disable. I repeat, only some usb devices do that, not all. That's why i didn't add this small guide up on my guide.
So you did as i instructed above and your pc successfully wakes up, but later in the day suddenly it doesn't wake up again.
Solution:
Open a terminal and do :
lsusb
At your keyboard device id information the 4 first digits are the vendor id and the 4 next digits are the product id (see screenshot)
Next do:
sudo nano /etc/udev/rules.d/10-wakeup.rules
Where "wakeup" enter your desired name of the script. Number 10 is the priority in case you have many other udev rules, the lower the number the 'rule' will be executed before the others.
Copy paste this and replace the vendor id and product id with your own wireless keyboard vendor id and product id.
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="062a", ATTRS{idProduct}=="4101" RUN+="/bin/sh -c 'echo enabled > /sys/bus/usb/devices/usb8/power/wakeup'"
*usb8 for me is my wireless keyboard (you can also see that in the screenshot (Bus 008)), replace it with your own.
Ctrl + O to save , Ctrl + X to exit and reboot.

- 2,553
-
6
-
2they are 2 different things. the 1st one is the answer to the wake up problem. the 2nd one is more like "How to create a rule to execute no boot" and it's just an "extra" since not everyone knows how to do that and there is no simple amateur guide for that. – Pavlos Theodorou Apr 14 '18 at 10:34
-
5This is indeed the right way to setup a device after connection; any other solution or script is just a dirty hack.
Improvement: use
$env{DEVPATH}
as device path in yourRUN
script. For example, this is the line for my Intel Bluetooth adapter:
– dav.garcia Feb 24 '20 at 18:21ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0aaa" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/power/wakeup'"
-
This is great and kind of works on my system. However, my MCE remote IR receiver seems to cause the system to wake up from suspend even when there is no button pressed. Any ideas what might be going on? – Vik Jun 16 '20 at 04:59
-
5I used simpler udev rule:
ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTRS{idVendor}=="046d", ATTR{power/wakeup}="disabled"
. See this answer: https://unix.stackexchange.com/a/532839/422471 – user570605 May 03 '21 at 11:50 -
This works for me on both ubunto and xubuntu machines, but with one 'slight' issue: I have a usb mouse and keyboard connected to a usb switcher which is connected to 2 laptops and 2 raspberry pi's. when I suspend one of the laptops it will wake up fine with a wiggle of the mouse or a press of any key. However, it will also wake up when I press the button to switch to another computer on the usb switcher - so I cannot suspend either laptop and work on another! is there a workaround for this? – matt cooper Aug 09 '22 at 17:31
-
@mattcooper I suggest you make a separate question about that, and link it here. I think the workaround is to disable wakeup by the switcher and use each devices' own buttons for wakeups. – jarno Aug 10 '22 at 18:12
-
1@jarno I did, my question .... no answers yet! but if you disable the switcher it doesnt work, and cant use the laptop buttons as they are closed and stacked. – matt cooper Aug 11 '22 at 13:36
None of the mentioned answers helped me. That's why I post here my own one.
Enabling/disabling wake up from suspend for USB devices
Tested in KDE neon 5.16.2, based on Ubuntu 18.04 but should work in any distribution.
Show the list of USB devices to identify the one you want to enable / disable:
grep . /sys/bus/usb/devices/*/product
you should obtain something like this:
/sys/bus/usb/devices/3-3/product:Cord Optical Mouse /sys/bus/usb/devices/3-4.3/product:802.11n WLAN Adapter /sys/bus/usb/devices/3-4.4/product:USB Receiver /sys/bus/usb/devices/3-4/product:USB2.0 Hub /sys/bus/usb/devices/4-4/product:USB3.0 Hub /sys/bus/usb/devices/usb1/product:EHCI Host Controller /sys/bus/usb/devices/usb2/product:EHCI Host Controller /sys/bus/usb/devices/usb3/product:xHCI Host Controller /sys/bus/usb/devices/usb4/product:xHCI Host Controller
Check wake up status of all USB devices:
grep . /sys/bus/usb/devices/*/power/wakeup
the result should be something like this:
/sys/bus/usb/devices/1-1/power/wakeup:disabled /sys/bus/usb/devices/2-1/power/wakeup:disabled /sys/bus/usb/devices/3-11/power/wakeup:disabled /sys/bus/usb/devices/3-3/power/wakeup:enabled /sys/bus/usb/devices/3-4.4/power/wakeup:disabled /sys/bus/usb/devices/3-4/power/wakeup:disabled /sys/bus/usb/devices/4-4/power/wakeup:disabled /sys/bus/usb/devices/usb1/power/wakeup:disabled /sys/bus/usb/devices/usb2/power/wakeup:disabled /sys/bus/usb/devices/usb3/power/wakeup:disabled /sys/bus/usb/devices/usb4/power/wakeup:disabled
In my case wake up is only enabled for the USB device 3-3 that, according to the previous list, is "Cord Optical Mouse".
I want to enable wake up from suspend only for wireless keyboard and disable it for the rest. The keyboard USB receiver is connected to a HUB and corresponds to 3-4.4 on the previous list ("USB Receiver").
Create a script that does the work:
To have root permissions:
sudo su
Then we create the file for the script (the file can be called "usbwakeup" or whatever descriptive you want):
nano /etc/init.d/usbwakeup
Contents of the file. Just adapt it to your needs by changing the "SCRIPT ACTIONS" section (I like adding comments to scripts in order to know what they actually do if I open them again someday):
#!/bin/bash # ####################### # GENERAL INFORMATION # ####################### # # - This script enables / disables wake up from suspend# for USB devices. # # - The script needs execution permissions. # # - For this script to be executed when the system starts, there must be # a symbolic link to it in /etc/rc3.d/ with priority S01 # (for example: /etc/rc3.d/S01usbwakeup) # ########################### # RELATED USEFUL COMMANDS # ########################### # # - Identify USB devices: # grep . /sys/bus/usb/devices/*/product # # - Check the status of "wake up of the suspension" of USB devices: # grep . /sys/bus/usb/devices/*/power/wakeup # # ################## # SCRIPT ACTIONS # ################## # # Disables wake up from suspend for optical mouse echo disabled > /sys/bus/usb/devices/3-3/power/wakeup # # Enables wake up from suspend for the wireless keyboard that I have connected to a USB 3.0 HUB in the USB port nr.4 echo enabled > /sys/bus/usb/devices/3-4.4/power/wakeup
Give it execution permissions:
chmod +x /etc/init.d/usbwakeup
Create a symbolic link in /etc/rc3.d/ for it to start on boot up:
sudo ln -s /etc/init.d/usbwakeup /etc/rc3.d/S01usbwakeup
By restart the system everything should work as specified in the script. The changes will be persistent as they will be executed with each system boot.
Reference

- 15,657

- 521
-
I just have found and interesting post where it's explained how to create a simple GUI for the same purpose. I haven't tested it but it could perhaps help someone trying to make it graphicaly and with the ease of a single click to enable/disable:
http://www.bernaerts-nicolas.fr/linux/74-ubuntu/220-ubuntu-resume-usb-hid
– call0fcode Jul 03 '19 at 12:08 -
1
Pavlos Theodorou's answer is very helpful. I would like to add that you can find the usb device that your mouse/keyboard is connected to at boot-up by piping dmesg through grep a couple of times, then egrep once, and finally using tail to make sure it was the most recent entry.
Using this method, you don't have to enable wake on ALL usb ports.
I put the following in my /etc/rc.local file and it finds my logitech receiver every time, even if moved from one usb port to another. Just substitute the name of your keyboard or mouse from dmesg in place of "Logitech K270"
KB="$(dmesg | grep "Logitech K270 as" | grep -o -P "usb.{0,5}" | egrep -o ".{0,3}$" | tail -1)"
echo enabled > /sys/bus/usb/devices/${KB}/power/wakeup
This works on boot, but doesn't seem to run on wake from suspend, so I had to put a script file in /lib/systemd/system-sleep/. Create it, set it as globally executable and give it a name that starts with a double digit number between 00 and 99. My script is as follows, again substite your keyboard/mouse verbage from dmesg:
#!/bin/sh
Action script to enable wake after suspend by keyboard or mouse
if [ $1 = post ]
then
KB="$(dmesg | grep "Logitech K270 as" | grep -o -P "usb.{0,5}" | egrep -o ".{0,3}$" | tail -1)"
echo enabled > /sys/bus/usb/devices/${KB}/power/wakeup
fi
if [ $1 = pre ]
then
KB="$(dmesg | grep "Logitech K270 as" | grep -o -P "usb.{0,5}" | egrep -o ".{0,3}$" | tail -1)"
echo enabled > /sys/bus/usb/devices/${KB}/power/wakeup
fi
For some reason I can't explain, the 'post' sleep if statement only works every other wake-up... but the 'pre' sleep if statement seems to work every time.

- 15,657

- 31
/sys/bus/usb/devices/<device id>/product
for a text description. – ntc2 Dec 12 '17 at 18:01grep . /sys/bus/usb/devices/*/power/wakeup
" but still didn't work. Perhaps it's because the keyboard and mouse are connected indirectly - wirelessly to a dongle which resides on the screen? Screen is connected via USB to the laptop. – AlikElzin-kilaka Mar 21 '18 at 20:42grep . /sys/bus/usb/devices/*/product
helped me to figure out what i'm looking at – Ben Yitzhaki May 05 '18 at 09:46/etc/rc.local
file. this post may help. – Sam Sep 27 '19 at 08:42echo enabled|sudo tee /sys/bus/usb/devices/*/power/wakeup
– Adam D. Sep 29 '19 at 15:30