Raspberry PI uhubctl permissions - linux

Trying to use uhubctl to control power to USB ports. I want to write a bash script to automate the task.
Right now I can use sudo commands to get it to turn off and on.
sudo ./uhubctl -l 1-1 -a 0
sudo ./uhubctl -l 1-1 -a 1
However I want to run these without sudo. I have added the permssions to the file /etc/udev/rules.d/52-usb.rules
Added the line SUBSYSTEM=="usb", ATTR{2109:3431}=="2001", MODE="0666" 2109:3431 is for Raspberry pi 4B.
And then run sudo udevadm trigger --attr-match=subsystem=usb and rebooted.
I keep getting the follwing errors
No compatible smart hubs detected!
Run with -h to get usage info.
There were permission problems while accessing USB.
To fix this, run this tool as root using 'sudo uhubctl',
or add one or more udev rules like below
to file '/etc/udev/rules.d/52-usb.rules':
SUBSYSTEM=="usb", ATTR{idVendor}=="2001", MODE="0666"
then run 'sudo udevadm trigger --attr-match=subsystem=usb'
What am I missing?

Related

Failed to open /dev/mem: Permission denied

Today, I tried to use this command on my raspberry Pi:
sox -t mp3 /home/pi/test.mp3 -t wav - | /home/pi/PiFmRds/src/pi_fm_rds -audio -
But I got this error message :
Failed to open /dev/mem: Permission denied.
Terminating: cleanly deactivated the DMA engine and killed the carrier.
sudo: ./sox : command not found
I've tried to place "sudo" before the command but I got the same error.
How can I resolve this please ? (and sorry if I did a mistake, I started playing with my raspberry today and this is also my first question on this website)
Thanks in advance !
Putting sudo in front of sox will not help you since I am pretty sure the error message "Failed to open /dev/mem" comes from pi_fm_rds. And that is still started without sudo.
You are actually executing two commands. sox is the first, and pi_fm_rds the second. You are sending the output of the first command to the second (via the pipe |).
To call pi_fm_rds with root access you can choose one of these three options:
Call pi_fm_rds with sudo
sox -t mp3 /home/pi/test.mp3 -t wav - | sudo /home/pi/PiFmRds/src/pi_fm_rds -audio -
Or add your user to the kmem group (which allows access to /dev/mem) - requires logout/reboot.
sudo usermod -a -G kmem userName
or make the program setuid root - or setgid kmem
chown root:root /home/pi/PiFmRds/src/pi_fm_rds
chmod u+s /home/pi/PiFmRds/src/pi_fm_rds

Always have to type 'sudo service ssh restart' on raspberry pi for controlling through laptop using putty

I am using my laptop's screen, keyboard and mouse for using raspberry pi 3 by using putty. but putty doesn't connect till I run 'sudo service ssh restart' command from terminal for which at least a keyboard is required which kinda defies the purpose. Is there any way to solve this or maybe I could put that command somewhere in the s card which has the os so that the command runs automatically at startup?
If you can't connect an keyboard try this, mount the SD card in another system and create symbolink links like this:
sudo ln -s /etc/init.d/ssh /etc/rc2.d/s03ssh
sudo ln -s /etc/init.d/ssh /etc/rc3.d/s03ssh
sudo ln -s /etc/init.d/ssh /etc/rc4.d/s03ssh
sudo ln -s /etc/init.d/ssh /etc/rc5.d/s03ssh
then restart and check the ssh connection

Auto start up midori browser is not working on Raspberry pi

I am trying to start browser in Raspberry Pi, on boot. These are the steps I've followed so far:
I have edited the .bashrc file from the root folder using this command:
sudo nano /home/pi/.bashrc
Added the following line at the end the file.
midori -e Fullscreen -a http://www.google.com
I restarted Raspberry Pi.
sudo reboot
It does not open the browser, on boot. How ever if I manually click on Terminal, it opens the browser.
I got a very simple solution of this. At first install midori on your pi.
sudo apt-get install midori
Then add the file that you want to auto start here.
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
For example you want to open google browser after reboot. Add this line to autostart file.
#midori -e Fullscreen -a http://google.com
Save the file and reboot your Pi. Now the google browser will auto start up every time you reboot.
I got the solution .
In new versions it is not supporting in this autostart file
sudo nano /etc/xdg/lxsession/LXDE/autostart
I changed the code to the below autostart file.
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
You can use crontab
sudo crontab -e
And add
#reboot command_you_want_to_run &
I solved using autostart of LXDE-pi and a sh file.
I had to install xautomation for simulate an user input
sudo apt-get install xautomation
In the home of pi I've created a sh file
touch start_browser.sh
I've inserted the following code in the file
#!/bin/sh
# running the browser on the main desktop
sudo -u pi epiphany-browser -a --profile ~/.config http://www.google.com/ --display=:0 &
# waits a few seconds, we wait that the browser has started successfully
sleep 15s;
# xautomation simulates the pressure on the F11 key for activate the browser in full screen mode on the main desktop
xte "key F11" -x:0
I added the executable permission on the sh file with chmod command
sudo chmod 755 start_browser.sh
I've modified the autostart files of LXDE-pi session
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
by adding the following command to run my sh file
#/home/pi/start_browser.sh
Now our browser should be start in full screen mode at each boot
If it does not, check that the Raspberry's configuration had enabled the boot into the desktop environment
sudo raspi-config
Select: 3 Enable Boot to Desktop/Scratch
Select: Desktop Log in as user 'pi' at the graphical desktop
Enjoy
In latest versions of raspberian you have to edit
sudo vi .config/lxsession/LXDE-pi/autostart
for this
#midori -e Fullscreen -a http://google.com
to work..

Is there any way to remove and insert network module remotely without losing connection?

I need to ssh to the server, remove the original network driver and insert a new one, but after I remove the original one, the connection will lose.
Is there any way to do it without losing connection.
The thing I want to do is:
$ ssh user#server
$ sudo rmmod igb
$ sudo insmod ./igb.ko
P.S., igb is the driver for one of Intel ethernet network card.
Thanks in advance.
Check this:
$ ssh user#server
$ sudo rmmod igb; sudo insmod ./igb.ko
Here the SSH server in the server will receive both the both commands even before executing the first command.

Beaglebone inittab issue

I am developing an application in beaglebone.
I want to add start up scripts to my Beaglebone but I can not find /etc/inittab.
I am using the image : Angstrom-Cloud9-IDE-GNOME-eglibc-ipk-v2012.05-beaglebone-2012.06.18.img.xz
I think in the previous versions of image there is /etc/initab but for the new distributions I could not find the inittab :/
I want to apply this : Automatic login on Angstrom Linux
but I can not because there is no /etc/inittab.
Where is the inittab in new distributions.
When I write uname -r it gives:
3.2.23
Regards
inittab has been replaced by systemd
This is how I did it for the serial console. You can probably adapt it easily for tty1 by replacing "serial-getty#..." by "getty#...", but I haven't tested it.
cp /lib/systemd/system/serial-getty#.service /etc/systemd/system/autologin#.service
rm /etc/systemd/system/getty.target.wants/serial-getty#ttyO0.service
ln -s /etc/systemd/system/autologin#.service /etc/systemd/system/getty.target.wants/serial-getty#ttyO0.service
Create the following script file in any location (/home/root/autologin.sh in my case)
#!/bin/sh
exec /bin/login -f root
Make it executable
chmod a+x autologin.sh
Edit /etc/systemd/system/autologin#.service and update the ExecStart command by adding the -n (Do not prompt the user for a login name) and -l (Invoke the specified login_program instead of /bin/login) options.
ExecStart=-/sbin/agetty -n -l /home/root/autologin.sh -s %I 115200

Resources