How To Check and Use Serial Ports Under Linux

by Vivek Gite on January 30, 2008 · 14 comments

How do I check and configure serial ports under Linux for various purposes such as modem, connecting null modems or connect a dumb terminal?

Linux offers various tools. Linux uses ttySx for a serial port device name. For example, COM1 (DOS/Windows name) is ttyS0, COM2 is ttyS1 and so on.

Task: Display Detected System's Serial Support

Simple run dmesg command
$ dmesg | grep tty
Output:

[   37.531286] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   37.531841] 00:0b: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
[   37.532138] 0000:04:00.3: ttyS1 at I/O 0x1020 (irq = 18) is a 16550A

setserial command

setserial is a program designed to set and/or report the configuration information associated with a serial port. This information includes what I/O port and IRQ a particular serial port is using, and whether or not the break key should be interpreted as the Secure Attention Key, and so on. Just type the following command:
$ setserial -g /dev/ttyS[0123]
Output:

/dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4
/dev/ttyS1, UART: 16550A, Port: 0x1020, IRQ: 18
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

setserial with -g option help to find out what physical serial ports your Linux box has.

Linux serial console programs

Once serial ports identified you can configure Linux box using various utilities:

  1. minicom- The best friendly serial communication program for controlling modems and connecting to dump devices
  2. wvidial or other GUI dial up networking program - a PPP dialer with built-in intelligence.
  3. getty / agetty - agetty opens a tty port, prompts for a login name and invokes the /bin/login command.
  4. grub / lilo configuration - To configure serial port as the system console

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 14 comments… read them below or add one }

1 Scott September 29, 2008

I don’t know if this is the place, but I’m looking for information that is similar. I have 2 machines setup through a null modem. I want to read through the com port from one machine to the other. The sending machine is running Windows sending through COM1: and the receiving computer is Linux Red Hat. Any help on this would be appreciated.

Reply

2 leszek September 30, 2008

another simple serial console program not mentioned is gtkterm.

Reply

3 Alessandro January 28, 2010

I want to advise you that probably there is an error in the last sentence “seserial with -g option help to find out what physical serial ports your Linux box has.”; isn’t it setserial?

Bye

Reply

4 Mike Bushroe April 12, 2011

I have 4 standard serial ports defined, /dev/ttyS0-4, but I added a PCI-E 16 port serial adapter, and I have not found a way to connect anything to the upper 16 ports.
How do you create the virtual links? what options do you give setserial to define the new ports?

Reply

5 arek April 17, 2011

it dosn’t work :( I can’t connect to my ASA using debian.

Reply

6 Joe Knifer November 1, 2011

Daemon is a program called getty used by UNIX/Linux systems. There are many different versions of getty. The first modem detected is /dev/ttys0 or /dev/ttys1. To create a link to the devices file so that you can view modem information. Type ln -s /dev/ttys1 /dev/modem.
It is essential to set the modem to AUTO ANSWER using getty.

download minicom from alioth.debian.org/projects/minicom.

create a modem config file by entering minicom -s from the root command line
select the options you want to configure using AT commands
connect to the modem by typing in minicom

Reply

7 AC November 10, 2011

Thanks very useful..save my time :)

Reply

8 abdel January 19, 2012

Hi,everybody
I have a serial PCI card with two ports but neither of them is working, on Linux fedora 16. I have tried using “gtkterm” and “minicom” but unfortunately I can’t make a serial connection to my Cisco lab. Here is my output when I issue the command: “setserial -g /dev/ttyS[0123]“.

/dev/ttyS0, UART: 16550A, Port: 0xec00, IRQ: 16
/dev/ttyS1, UART: 16550A, Port: 0xe880, IRQ: 16
/dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
/dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

also I want to mention that when I try to connet throught the terminal it generates a message like so: ” Cannot open /dev/ttyS0: Permission denied”.
any help please.
abdel

Reply

9 Tom Schuneman January 23, 2012

Check the permissions on /dev/ttyS0… Likely problem is it’s owned by root, and is part of the uucp group. Add yourself to the uucp group, and all should be better. I’m curious to know if this is enough for you as I am having problems communicating with a serial port on Linux as well. I got past the permissions stuff, but it is still not working.

Reply

10 abdel January 25, 2012

Thanks Tom,
I actually I tried but it’s does not work, still says “permission denied”. I would appreciate if you explain to me step by step the procedure how to do it, I’m knew to Linux.
Best Regards
Abdel

Reply

11 Tom Schuneman January 25, 2012

1) ls -la /dev/ttyS0 — This will report the permissions on the port. Typically, this will say crw-rw—- 1 root uucp. The “c” in the string indicates that it’s a “character device” the first “rw” indicates that the owner has read/write permission. The second “rw” means that the group has read/write permissions. The “—” indicates that the rest of the world has no permissions. After the “—-”, “root” indicates that the owner of the device is root, and that the group id is “uucp”. So, you either need to be root, or a member of the uucp group to have read/write access to the port.

2) To add yourself to the uucp group (to get read/write access), you need to edit the file /etc/group, and add your user name to the line that begins with “uucp:” User names are separated by commas, so add a comma, then your user name to the end of the line. You will need root permissions to edit this file.

3) log out, and log back in because group associations are made at login time, and are not queried on each request.

Reply

12 abdel January 28, 2012

Thanks Tom,
here is my output from the group file I have added my username to it but does not work.

abdelinux:x:1000:uucp,adm,abdelinux,

I will just give up.Thanks a lot for your help I relay appreciate it.

Reply

13 Tom Schuneman January 30, 2012

Your entry in /etc/group is incorrect. If you read my previous post, I said to add your user id to the line that _begins_ with uucp. You added uucp to the group of users that can access your account. You want an entry in the /etc/group file that looks something like:

uucp:x:14:uucp,abdelinux

The critical element is that it’s the line that begins with uucp

Reply

14 abdel January 31, 2012

Hi Tom,

It works. I just add my username to ” dialout ” and it worked fine. Iwould like to thank you for you time and support.

Best Regards
Abdel

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 9 + 8 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: