linux serial port connection with cu command - linux

there is a network device on my ttyUSB0 port. I can access it with sccren command on linux, but when I try to connect with cu command I get this error:
sudo cu -s 9600 -l /dev/ttyUSB0
cu: open (/dev/ttyUSB0): Permission denied
cu: /dev/ttyUSB0: Line in use
How can I connect with cu command?

Usually it's just the file permissions on /dev/ttyUSB0 that aren't set after connecting the device:
sudo chown $USER /dev/ttyUSB0
Or add yourself to the dialout group:
sudo usermod -a -G dialout $USER

Related

How to run a sudo command silently on the server?

I need to execute this command on Linux server.
string command = $"sudo iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport {port} -j ACCEPT";
When I run the app in VirtulBox, the terminal asks me for a password.
Will this also happen on the server? I can't login to the server and don't know the password.
How can I run the command so that it does not ask for password?
Login to the terminal as root. Make a backup of your /etc/sudoers file.
# cp /etc/sudoers /root/sudoers.bak
Then edit this file by using the visudo command:
# visudo
Edit or append this line, replacing username with the user that will be running your script:
username ALL = NOPASSWD: /usr/sbin/iptables
Save and exit the file.
Test it by executing sudo, from your user account:
$ sudo iptables -V
Now your user can use sudo to execute the iptables command.
If you whant to do this from Linux machine:
You can writ a script with:
sshpass -p "PASSWORD" user#server
and give only execute premition.

Raspberry PI uhubctl permissions

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?

python serial [Errno 13] Permission denied: /dev/tty*

I try to open serial port, but cant with permission.
But works with sudo.
How i can get permission for serial port?
sas#sas-linuxmint ~ $groups sas
sas : sas adm tty dialout cdrom sudo dip plugdev lpadmin sambashare
This my code:
def get_serial_port():
ser_devs = [dev for dev in os.listdir('/dev') if dev.startswith('tty')]
for i in ser_devs:
port = "/dev/" + i
try :
ser = serial.Serial(port, 19200)
if ser.is_open:
print("OPEN!!!!!!!!!!!!!!!!!!!!!! {}".format(port))
ser.close()
except serial.SerialException as e:
print(e, port)
return None
output:
[Errno 13] could not open port /dev/ttyprintk: [Errno 13] Permission denied: '/dev/ttyprintk' /dev/ttyprintk
for all ports.
I tried change mod for port, but it doesn't work too
sudo chmod 766 /dev/ttyS10
sudo chmod -R a+rw /dev/ttyS10
sudo chmod 777 /dev/ttyS10
sudo chmod 666 /dev/ttyS10
I tried using the following command:
sudo gpasswd --add ${USER} dialout
To add dialout to my group but with no luck. The following worked for me: (assuming tty1 is the name)
sudo chmod 666 /dev/tty1
may be 2 years late but, you simply add your user to the tty group
eg:
sudo usermod -a -G tty $USER
link

-su: /dev/tty: No such device or address

could please someone explain to me why this happens?
# su - someone -s /bin/bash -c "ls -la /dev/tty"
crw-rw-rw- 1 nobody nogroup 5, 0 Dec 7 20:53 /dev/tty
# BUT:
# su - someone -s /bin/bash -c "echo hello > /dev/tty"
-su: /dev/tty: No such device or address
I'm trieng to build a docker Container which has two services inside. Those services a startet by a Shell-Script:
CMD ["./starter.sh"]
Withing the Dockerfile I have redirected the Logs to /dev/stderr or /dev/tty
# None of the following works:
RUN ln -sf /dev/tty /var/log/thelog.log
RUN ln -sf /dev/stdout /var/log/thelog.log
RUN ln -sf /dev/stderr /var/log/thelog.log
The problem is that I'm trying to run one of the services as not root (su -
someone -c "service"), which give's the following error:
unable to open log file [/var/log/thelog.log]: [6] No such device or address
How could I solve this problem? I want the logs to be linked to /dev/* AND want to run the User as non-root. Also I tried to add the User to the group tty, which did not work out.
Thanks.
The manpage for su states that the executed command will have no controlling terminal. Any writes to /dev/tty will return the ENXIO error:
$ errno ENXIO
ENXIO 6 No such device or address
sudo does allocate a controlling terminal:
sudo -u someone /bin/bash -c "echo hello > /dev/tty"
There's no need for you to make a symbolic link to /dev/tty (/dev/stdout and /dev/stderr is enough) or use sudo if you use the USER directive in the Dockerfile or supervisor.

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

Resources