This is a step-by-step guide to using the serial port from a program running under Linux; it was written for the Raspberry Pi serial port with the Raspbian Wheezy distribution. However, the same code should work on other systems. An application developer and software tester with more than 20 years in the IT industry working on Windows, UNIX and Linux. Updated August 14, 2019 In this guide, you will discover a number of different ways to open an application using Ubuntu.
Question: I need to access the management terminal of a hardware switch/router (e.g., Cisco Catalyst or HP ProCurve) via its console port. The switch console port is connected to the serial port of my Linux box. How can I connect to the serial port from a Linux terminal?
First of all, let's assume that you have already connected the serial port of your Linux box to a switch console port via a serial cable.
To connect a Linux terminal to the serial port of your Linux system, you can use a command-line screen manager tool called screen.
Install screen on Linux
To install screen on Debian, Ubuntu or Linux Mint:
To install screen on CentOS, Fedora, or RHEL:
$ sudo yum install screen
Connect to a Serial Port with screen utility
Traditionally in Linux, the first serial port (COM1) is assigned a name /dev/ttyS0, the second serial port (COM2) assigned /dev/ttyS1, etc. If you specify a serial port name as the first argument of the screen command, the current terminal window where you run screen will be directly connected to the serial port.
Thus, to connect to a serial port, simply run the following command from a terminal:
Optionally, you can specify baud rate (e.g., 1200, 9600, 19200) as the second parameter as follows.
$ screen /dev/ttyS0 9600
Once connected to a serial port, you will then be able to access the switch console port from the terminal.
To terminate the current screen session, type 'Ctrl-A'+'k'. If you want to temporarily detach from the screen session, type 'Ctrl-A'+'d'. After detached, you can re-attached to the session later by running:
Download this article as ad-free PDF (made possible by your kind donation):
Subscribe to Ask Xmodulo
Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.
Support Xmodulo
Did you find this tutorial helpful? Then please be generous and support Xmodulo!
I am trying to make a connection via serial console to a serial device from terminal.- I have a DB9-M cable and a USB to serial cable.
- Current software is Ubuntu 17.04
- Terminal is Bash
I downloaded the ‘screen’ program, but I believe I am missing something else.
Ubuntu Serial Port Tool
The command I am using is:However, it disconnects after a few seconds because it finds no device to connect to.How do I find a list of connected devices to make sure that the device is not using a different name?