Saturday 26 February 2011

Permissions



Now the serial port has been found, are we allowed to use it?

If you get this when logged in as a normal user:

$setserial /dev/ttyS0
/dev/ttyS0: Permission denied

You do not have permission to access the serial port.

____________________



























If we look at the permissions associated with a serial port:

ls -l /dev/ttyS*
crw-rw---- 1 root dialout 4, 64 2011-02-17 09:13 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 2011-02-17 09:13 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 2011-02-17 09:13 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 2011-02-17 09:15 /dev/ttyS3

We see the serial ports are owned by 'root', and are in the group 'dialout'.

Now, you could change the owner or group of the serial ports, but a better way is to join the group for the serial device.

To see which groups we currently belong to, use the 'groups' command.

$groups
users video

No mention of 'dialout'. To add us in, we can either, as root, use the usermod command to add in our own username against the 'dialout' group, or use one of the more sophisticated configuration tools included with most distributions.

First, here's the usermod method. The current user is indicated by the whoami command.

$whoami
fred

So we need to add 'fred' to the 'dialout' group. The -G option adds users to groups, but it also removes you from any groups you do not mention. The -a option simplifies this, so we only need to note the new groups we are joining, but we still need the -G option. Here's how it looks:

$usermod -a -G dialout fred

Now, this is the case for most distributions, however SUSE has modified this command, and removed the -a option. As of SUSE 11.3, there is an -A option, which can be used like this:

$usermod -A dialout fred

But for previous versions of SUSE, only the -G option was available, so all groups, even ones that the user is already a member of, must be mentioned too:

$usermod -a -G dialout,users,video fred

So, that's the usermod method. The other way is to use the distributions configuration tools. There are too many different ones for me to cover here, but look for something like 'User and group management'. Select your user, and go to the groups area, then associate the user with the 'dialout' group. You will need the root password to do this.

We have now joined the group to access our serial ports, why do we get this, then?

$groups
users video

There's one more stage to perform, and that is to log out and log back in again for the group change to take effect.

Following is a list of some of the popular distros, and their permission settings.


     
Distro
Owner
Group
CentOS 5.5
root
uucp
CentOS 6.2
root
dialout
Debian 6.0
root
dialout
Debian 7.0
root
dialout
Fedora 17
root
dialout
Fedora 18
root
dialout
Linux Mint 13
root
dialout
Linux Mint 14
root
dialout
SUSE 11.4
root
dialout
SUSE 12.1
root
dialout
SUSE 12.2
root
dialout
SUSE 12.3
root
dialout
Ubuntu 10.04
root
dialout
Ubuntu 11.10
root
dialout
Ubuntu 12.04
root
dialout
Ubuntu 12.10
root
dialout
Ubuntu 13.04
root
dialout





5 comments:

  1. This is a rather old post, but for the record:
    SLES 11.0 has "usermod -A" too.

    ReplyDelete
  2. Thanks for that, BikeMan. Just checked SUSE 11.4 & 12.1. They both use the "usermod -A" method, too.

    ReplyDelete
  3. I found this post absolutely useful, in fact solve my problem.

    My hint to the readers: a simplest way to add users to groups is sudo

    Adding a user to a group: sudo adduser user group
    Removing a user from a group: sudo deluser user group

    ReplyDelete
  4. thanks a bunch - now i shant have to load windows for my cisco work, very kind of you

    ReplyDelete
  5. Thanks big help getting JT65hf working :-)

    ReplyDelete