I have a CentOS 7 headless system with no serial ports. I sometimes want to access the server using a serial cable, so I plug in a USB serial cable (to my laptop's serial port) but I can't get a console/BASH from the connection.

Is there something I have to do to tell the kernel to always create a serial console on appearance of a USB serial port?

  • often headless systems have UART or JTAG pins for RS-232 which should be more sensible than using USB to serial. – Rui F Ribeiro Dec 16 '15 at 3:08

EDIT: This won't work if you have a recent udev version, because udev prevents you from starting long-lived background processes in RUN scripts. You may or may not be able to get around this by prefixing the getty command with setsid but in any case it's discouraged if not outright disallowed. If you have a system which uses systemd then there is another way to achieve this, which I hope someone will supply with another answer. In the meantime, I'm leaving this answer here in case it works for you.

You cannot use a USB serial port as a console because USB is initialized too late in the boot sequence, long after the console needs to be working.

You can run getty on a USB serial port to allow you to log in and get a shell session on that port, but it will not be the system's console.

To get getty to start automatically, try this udev rule:

ACTION=="add", SUBSYSTEM=="tty", ENV{ID_BUS}=="usb", RUN+="/usr/local/sbin/usbrungetty"

Put that in a rules file in /etc/udev/rules.d and then create this executable script /usr/local/sbin/usbrungetty:


/sbin/getty -L "$DEVNAME" 115200 vt102 &
| improve this answer | |
  • 2
    With judicious use of SYSTEMD_WANTS you should be able to start serial-getty@$name.service directly, eliminate the shell script middleman entirely, and have proper full control over the resultant service. This has the added bonus of conforming to the precept that udev children and grandchildren spawned from rules not be long-running processes. – JdeBP Dec 16 '15 at 7:53
  • You're correct, there's a different "right way" to do this in the systemd world. I didn't include it because I don't know systemd. As for the long-running process restriction on udev-spawned scripts, my understanding is that it's okay if you start something in the background, as long as the actual script udev launches terminates quickly. – Celada Dec 16 '15 at 7:58
  • No. As of 2012, grandchildren must be short-lived, too, now. Another benefit of not having a hand-written getty invocation is that serial-getty@.service is well known as the place to tweak settings such as TERM. – JdeBP Dec 16 '15 at 8:13
  • I stand corrected. – Celada Dec 16 '15 at 8:18
  • 1
    Since CentOS7 uses systemd, can someone provide an example of how to do this? – TSG Dec 16 '15 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.