1

I have an embedded device (Nvidia Jetson TX2 running Ubuntu 16.04) in a carrier board and need to use the serial port. The serial port on the carrier board maps to ttyS0 which by default is owned by root and belongs to group tty:

crw--w----  1 root tty       4,  64 Aug  1 13:34 ttyS0

I've added user ubuntu to group tty (which is what I log in as) however by default the group doesn't have read access to ttyS0.

sudo chmod g+r /dev/ttyS0 fixes it, but this doesn't persist through a reboot. I've tried creating various udev rules (99-z_setup.rules):

KERNEL=="ttyS0", NAME="ttyS0", SYMLINK+="my_tty", GROUP:="tty", MODE:="0660", OWNER:="ubuntu"

or

KERNEL=="ttyS0", NAME="ttyS0", SYMLINK+="my_tty", GROUP:="tty", MODE:="0660"

or

KERNEL=="ttyS0", NAME="ttyS0", SYMLINK+="my_tty", GROUP="tty", MODE="0660"

these result in:

lrwxrwxrwx  1 root root           5 Aug  1 13:34 my_tty -> ttyS0
crw--w----  1 root tty       4,  64 Aug  1 13:34 ttyS0

so I still can't access it. I also tried

KERNEL=="ttyS0", ACTION=="add", PROGRAM="/usr/bin/sudo /home/ubuntu/bin/setup_tty.sh"

with setup_tty.sh containing

#!/bin/bash

chmod g+r /dev/ttyS0
echo "setup_tty ran" >> /home/ubuntu/bin/tty.log

It echos to the tty.log file so I know the script runs, but the permissions are still

crw--w----  1 root tty       4,  64 Aug  1 13:44 ttyS0

It's like the group / owner / mode settings are being ignored or being overwritten. I've searched and there are a lot of similar questions, but the answer to them always seems to be to add the user to group tty or dialout. My user account is already a member of both of those but no dice since for some reason by default, the group doesn't have read permission.

I checked the /etc/login.defs and found these lines:

#       TTYPERM         Login tty will be set to this permission.
#
# If you have a "write" program which is "setgid" to a special group
# which owns the terminals, define TTYGROUP to the group number and
# TTYPERM to 0620.  Otherwise leave TTYGROUP commented out and assign
# TTYPERM to either 622 or 600.
#
# In Debian /usr/bin/bsd-write or similar programs are setgid tty
# However, the default and recommended value for TTYPERM is still 0600
# to not allow anyone to write to anyone else console or terminal

# Users can still allow other people to write them by issuing
# the "mesg y" command.

TTYGROUP        tty
TTYPERM         0600

I changed the TTYPERM value to 0660 and rebooted, but it made no difference.

Any ideas how I can make this tty have a mode other than 640 after reboot?

This will probably be the answer-I ran journalctl | grep tty and among other things found this output:

Aug 02 11:05:45 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0.
Aug 02 11:05:47 TX2-JUDY systemd[1]: serial-getty@ttyS0.service: Service hold-off time over, scheduling restart.
Aug 02 11:05:47 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0.
Aug 02 11:05:47 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0.
Aug 02 11:05:47 TX2-JUDY systemd[1]: serial-getty@ttyS0.service: Service hold-off time over, scheduling restart.
Aug 02 11:05:47 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0.
Aug 02 11:05:47 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0.
Aug 02 11:05:47 TX2-JUDY systemd[1]: serial-getty@ttyS0.service: Service hold-off time over, scheduling restart.
Aug 02 11:05:47 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0.
Aug 02 11:05:47 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0.
Aug 02 11:05:48 TX2-JUDY systemd[1]: serial-getty@ttyS0.service: Service hold-off time over, scheduling restart.
Aug 02 11:05:48 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0.
Aug 02 11:05:48 TX2-JUDY systemd[1]: Started Serial Getty on ttyS0.
Aug 02 11:05:48 TX2-JUDY systemd[1]: serial-getty@ttyS0.service: Service hold-off time over, scheduling restart.
Aug 02 11:05:48 TX2-JUDY systemd[1]: Stopped Serial Getty on ttyS0.
Aug 02 11:05:48 TX2-JUDY systemd[1]: serial-getty@ttyS0.service: Start request repeated too quickly.
Aug 02 11:05:48 TX2-JUDY systemd[1]: Failed to start Serial Getty on ttyS0.

so it appears some other service (not sure what Getty is) is trying to use ttyS0.

  • Rather than echo "setup_tty ran" >> /home/ubuntu/bin/tty.log, it might be more informative to do ls -ld /dev/ttyS0 >> /home/ubuntu/bin/tty.log.  Please do not respond in comments; edit your question to show the result of the above suggestion. – G-Man Aug 2 '18 at 4:06
  • What does grep tty /usr/lib/udev/rules.d/* (or /lib/udev/rules.d/, depending on your distro) and grep tty /run/udev/rules.d/* show? Possibly there is a 99-zzz_do_these_last_i_mean_it.rules hiding somewhere :-) – ErikF Aug 2 '18 at 5:03
  • @ErikF - I verified it was the last udev rule in that directory. – schrödinbug Aug 2 '18 at 15:13
  • Not sure what goes wrong, but you can do udev debugging be restarting udevd in verbose mode. – dirkt Aug 2 '18 at 16:00
1

If you are using login, look at /etc/login.defs, entry TTYPERM.

General debugging advice: At the start of your script you should use this to catch error output from your commands, also verify that the device entry already exists.

exec >> /home/ubuntu/bin/tty.log 2>&1
  • It won't let me +1 for the exec tip, but that showed me a typo in my setup_tty.sh script, however fixing that still didn't work--good tip though. Also I added what I found in the login.defs. – schrödinbug Aug 2 '18 at 15:03
  • Sometimes it's easier to add the chmod to a local startup file than to fight systemd. – RalfFriedl Aug 2 '18 at 17:30
0

So it turns out that in my case, ttyS0 is the serial console for the TX2 so trying to use it the way I was going to would be more pain that it's worth. It appears ttyTHS2 is also available and already has the permissions required. Not a particularly satisfying answer, but the best way forward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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