57 lines
1.6 KiB
Markdown
57 lines
1.6 KiB
Markdown
# Linux - connect to a serial port with screen
|
|
|
|
There are a bunch of programs out there, that can get you connected to a serial port of a switch, but using `screen` was the best and easiest solution I've found. Works perfectly in the CLI, can be run in the background, and easy to set up - if it is not already installed.
|
|
|
|
It worked with various combinations of serial-to-usb-cables, Cisco switches, and Linux machines. Let us start with the command itself:
|
|
|
|
* `sudo screen /dev/ttyUSB0 9600`
|
|
* `sudo screen` - run `screen` as sudo
|
|
* `/dev/ttyUSB0` - the tty number of the usb cable / adapter
|
|
* `9600` - the speed of the serial connection
|
|
|
|
You can kill the session with `CTRL` + `a`, then `k`, and confirm it with `y`.
|
|
|
|
### Finding the device / the tty number
|
|
|
|
Find the tty number while you are already connected:
|
|
|
|
`sudo dmesg | grep tty`
|
|
|
|
Output:
|
|
|
|
```markdown
|
|
kuser@pleasejustwork:~$ sudo dmesg | grep tty
|
|
[ 0.134050] printk: console [tty0] enabled
|
|
[1724834.635665] usb 3-1: FTDI USB Serial Device converter now attached to ttyUSB0
|
|
```
|
|
|
|
Shows the device while plugging it in:
|
|
|
|
`sudo dmesg -wH | grep tty`
|
|
|
|
Output:
|
|
|
|
```markdown
|
|
kuser@pleasejustwork:~$ sudo dmesg -wH | grep tty
|
|
[sudo] password for kuser:
|
|
[ +0,000022] printk: console [tty0] enabled
|
|
[ +0,001283] usb 3-1: FTDI USB Serial Device converter now attached to ttyUSB0
|
|
```
|
|
|
|
This is helpful if you are connected to multiple devices.
|
|
|
|
### Finding the correct speed
|
|
|
|
I haven't had to change this yet, but just in case:
|
|
|
|
`sudo stty -F /dev/ttyUSB0`
|
|
|
|
Output:
|
|
|
|
```markdown
|
|
kuser@pleasejustwork:~$ sudo stty -F /dev/ttyUSB0
|
|
speed 9600 baud; line = 0;
|
|
-brkint -imaxbel
|
|
```
|
|
|
|
---
|