0

I have been trying to find a solution for 2 days but I wasn't able to find one. I want to change the permission of the /dev/ttyAMA0 but seems to be impossible. I tried with sudo chmod 777 /deb/ttyAMA0 but at the following minute the port recovered old permissions for read, write and execute. The next thing that I tried was writing an udev rule with the following code: KERNEL=="ttyAMA0", MODE="0777, but nothing end with success.

I want to read information from an antenna that is connected on the serial port ttyAMA0, the problem is that I am not able to read the information unless I will give read permissions.

When I try to sudo adduser $USER tty the output is the following:The user pi' is already a member of tty'. Moreover, when I execute a script to access the /dev/ttyAMA0 the result is:

Permission denied: '/dev/ttyAMA0'.

I have these permissions on ttyAMA0 port:

crw--w---- 1 root tty 204, 64 Jul 5 11:15 ttyAMA0

the output of lsof /dev/ttyAMA0 is the following:

agetty 800 root 0u CHR 204,64 0t0 1157 /dev/ttyAMA0
agetty 800 root 1u CHR 204,64 0t0 1157 /dev/ttyAMA0
agetty 800 root 2u CHR 204,64 0t0 1157 /dev/ttyAMA0

I used this command to kill the process:

sudo systemctl stop serial-getty@ttyAMA0.service

Now I am able to change the permissions without any automatic change in permissions each minute. The problem now is that each time I reboot the Raspberry the permissions change to the default configuration.

I switched the serial ports ttyAMA0 and ttyS0 to get a better control of the Baudrate, that is the reason why the ttyAMA0 port has crw--w---- instead of crw-rw----.

I don't know what else I can do.

  • What are you trying to achieve by changing the permissions? What does not work if you leave the permissions alone? You should not be changing the permissions. – joan Jul 6 '18 at 21:57
  • I want to read information from an antenna that is connected on the serial port ttyAMA0, the problem is that I am not able to read the information unless I will give read permissions – Sergio Prieto Jul 8 '18 at 7:00
0

One plausible cause of your issue is that /dev/ttyAMA0 is used as a boot console in /boot/cmdline.txt. You should remove the console=/dev/xxx,115200 if you intend to use the serial port as a general-purpose device and not as a boot console.

1

Please, don't touch the permissions, that's not a good way to get access.

Instead, add yourself to the group tty which owns the device and has read/write access:

$ ls -l /dev/ttyAMA0 
crw-rw---- 1 root tty 204, 64 Jun 20  2016 /dev/ttyAMA0

You may easily do that using:

sudo adduser $USER tty

$USER is the name you used to log in with (echo $USER on command line will show your name) so you can use that command 'as is' and do not need to change anything.

  • I have tried it and the output is the following:The user pi' is already a member of tty'. Moreover, when I execute a script to access the /dev/ttyAMA0 the result is: Permission denied: '/dev/ttyAMA0'. I have these permissions on ttyAMA0 port: crw--w---- 1 root tty 204, 64 Jul 5 11:15 ttyAMA0 – Sergio Prieto Jul 8 '18 at 8:09
  • @SergioPrieto try lsof /dev/ttyAMA0 to find out if someone else's using the port? – lenik Jul 8 '18 at 8:11
  • the output of the lsof command is the followingagetty 800 root 0u CHR 204,64 0t0 1157 /dev/ttyAMA0 agetty 800 root 1u CHR 204,64 0t0 1157 /dev/ttyAMA0 agetty 800 root 2u CHR 204,64 0t0 1157 /dev/ttyAMA0 – Sergio Prieto Jul 8 '18 at 8:15
  • @SergioPrieto well, likely you have terminal sessions waiting for users on those terminals. try to killall agetty, but be careful, it might kill something useful =) – lenik Jul 8 '18 at 8:48
  • I used this command to kill the process:sudo systemctl stop serial-getty@ttyAMA0.service, now I am able to change the permissions without any automatic change in permissions each minute. The problem now is that each time I reboot the Raspberry the permissions change to the default configuration. – Sergio Prieto Jul 8 '18 at 11:00
0

The permissions are changing because another process is accessing the serial link.

You need to identify and deactivate that process (ls -l /dev/ttyAMA0 will probably show the group).

Once that process is deactivated the permissions will be correctly set by Linux without you having to do anything else.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.