If you were to do this the “official” way, then you’d need to know that files in “/dev
” are not real files. They are actually drivers, in RAM, pretending to be files. Changing permissions is somewhat different. To modify defaults the “udev
” system is used.
If you browse in “/etc/udev/rules.d/
”, then you will find human-readable files. Each file has a number of ways to identify a file in “/dev
”. Once identified there are a number of things udev
can edit. One of those will be file permissions. This is the “MODE
”, a.k.a., permissions. Example:
grep MODE /etc/udev/rules.d/*
You’ll find owner, group, and mode (chmod
) can be set. You’d be interested in MODE
.
The hard part is to identify only your files. I will start by saying that you should look closely at the output of “ls -l /dev/ttyTHS1
” before you modify it. If this is group dialout
, then you should instead add your user to that group as a supplemental group instead of changing the file itself. If that file is group tty
, then this should not be altered. The reason for being group tty
would be that the serial port is already used as a serial console. One can disable serial console (not really a good idea), and the permissions will revert to group dialout
. An example of how to append this group to your regular user is this (I’m pretending your user name is “nvidia
”; adjust to be whatever your user name really is):
sudo usermod -aG dialout nvidia
It’s a really bad idea in terms of security to add your user to supplemental group root
, but you could add your user to supplemental group gpio
if that is the group of those files. Most likely the group is root
.
An interesting topic on udev
, which is used to control attributes of device special files the proper way at bootup:
https://askubuntu.com/questions/15570/configure-udev-to-change-permissions-on-usb-hid-device
Go to “/etc/udev/rules.d/
”. The files there are human readable. Examine a few. Notice how they start by providing attributes of a file which identify which file(s) the rule will apply to. Some of those attributes are based on USB descriptors (the idVendor
and idProduct
), and only matter for USB devices. Others might name a file pattern. An example is if you see:
KERNEL=="ttyUSB[0-9]"
…the above uses a regular expression to find a file the kernel has assigned name pattern “ttyUSB0
” through “ttyUSB9
” to.
The inverse is this, which identifies files not using that name pattern:
KERNEL!="ttyUSB[0-9]"
The reason for this is that sometimes there are a series of rules, and reaching some test condition might invoke a “GOTO
” statement to skip some lines. I have not used this on GPIO, but in theory you could create a new file in “/etc/udev/rules.d/
” which has this as identity of files you are looking at:
KERNEL=="gpiochip[0-9]"
Do not change the group unless you know that group exists. For example, you could search for group “gpio
” via either:
A. grep -i 'gpio' /etc/group
B.
less -i /etc/group
# The "/" starts a regular expression search:
/gpio
If you don’t have a group called “gpio
”, then you could create it (this is only one way of multiple):
# There are options to this, e.g., setting a specific group number; useful
# if you are creating a group which is part of the system and traditionally
# from a lower number.
sudo addgroup gpio
Take a look at your own group since Ubuntu (and most Linux flavors) create a group for each user. If your login name is “someone
”, then this will find your group:
grep 'someone' /etc/group
Let’s say you are a member of more than one group, then the above will return more than one result. This includes supplemental groups you are in. If a group exists, and you add yourself to it (for example, remember earlier I mentioned that you can add your user to supplemental group “dialout
”?), that will show up. If group gpio
does not exist, and you manually added it, then no user will be part of it yet.
To add yourself to group gpio
(assuming your user name is “someone
”; adjust for your user name):
sudo usermod -aG gpio someone
If you also happen to have a udev
rule which changes the gpiochip[0-9]'
to OWNER
of root
, GROUP
of gpio
, and MODE
of 0660
, then any user of gpio
group can use those device special files.
In summary: It is better to use udev
to modify permissions and ownerships in /dev
, and to create a new group or reuse an existing group, and then add your user to that group. Manual chmod
might not always work the way you expect because those are not real files.