plink for scripted connections, as the standard GUI executable lacks command-line flags for baud rate and data bits. This guide details how to configure these settings manually within the application or via the reliable alternative tool designed for automation.
Why Command-Line Flags Fail for Serial Configuration
The most common source of confusion when attempting to automate serial connections with PuTTY is the assumption that the putty.exe binary accepts configuration flags similar to those found in SSH clients like OpenSSH. Users often search for a flag such as -sercfg or attempt to append speed parameters directly to the command line, only to find that the program ignores them or throws an error. The standard PuTTY graphical frontend is designed primarily for interactive use, meaning it does not parse complex connection parameters from the terminal invocation.
This limitation exists because serial communication involves multiple nuanced settings beyond just the IP address or hostname. Parameters such as baud rate, data bits, stop bits, parity, and flow control must be explicitly defined. Without a dedicated scriptable interface, the application defaults to generic values that rarely match the requirements of embedded devices, routers, or legacy hardware. Consequently, relying on the main putty executable for automated tasks is fundamentally flawed and will not yield a stable connection.
Configuring Serial Settings via the GUI
To establish a working serial connection, you must first define the parameters within the PuTTY configuration window. This process ensures that every time you launch the session, the correct handshake protocols are used. Start by opening the PuTTY application on your Linux system. In the initial screen, locate the "Session" category at the top of the left-hand menu tree.
- Select Connection Type: Change the "Connection type" dropdown from "SSH" to "Serial". This action reveals new fields specific to serial communication, replacing the host name input box.
- Specify the Port: Enter the path to your serial device in the "Serial line" field. On most Linux distributions, this is typically
/dev/ttyS0for the first physical port or/dev/ttyUSB0if you are using a USB-to-serial adapter. - Set Speed: Input the baud rate in the "Speed" box. Common values include 9600, 115200, or 19200, depending on the target device's specifications.
Once the basic connection details are entered, you must configure the advanced serial parameters. Click on "Serial" in the left-hand menu under the "Connection" section. Here, you can adjust the following critical settings:
- Data bits: Usually set to 8.
- Stop bits: Typically 1.
- Parity: Set to None unless the device documentation specifies otherwise.
- Flow control: Select "None" for most direct console connections, or "XON/XOFF" if software flow control is required by the remote system.
After configuring these values, return to the "Session" category. Give your connection a name in the "Saved Sessions" box and click "Save". This creates a persistent configuration file that PuTTY will recall automatically, eliminating the need to re-enter parameters every time.
Using Plink for Scripted Connections
If you require non-interactive access to a serial device, such as running commands in a bash script or automating device provisioning, the graphical PuTTY client is insufficient. Instead, you should use plink, which is part of the PuTTY suite but designed specifically for command-line usage. Unlike the main putty binary, plink supports a wider range of options for establishing connections without a GUI.
To connect via serial using plink, you must specify the connection type and the serial line arguments. The syntax generally follows this structure:
plink -serial /dev/ttyUSB0 -sercfg 115200,8,1,n,n -l username -pw password
In this command, the -serial flag indicates the connection mode. The -sercfg option is unique to plink and allows you to pass the baud rate, data bits, stop bits, parity, and flow control in a single string. The format is baudrate,databits,stopbits,parity,flowcontrol. For example, 115200,8,1,n,n sets 115200 baud, 8 data bits, 1 stop bit, no parity, and no flow control.
It is important to note that plink handles serial connections differently than SSH. It does not encrypt the traffic by default in the same way, so ensure that sensitive data transmission is handled appropriately. Additionally, verify that your user has read/write permissions for the specified /dev/tty* device, or use sudo if necessary.
Troubleshooting Common Serial Issues
Even with correct parameters, serial connections can fail due to permission issues or conflicting drivers. If plink reports that it cannot open the serial port, check the ownership of the device file using ls -l /dev/ttyUSB0. You may need to add your user to the dialout group on Debian-based systems to gain access.
Another frequent issue is incorrect flow control settings. If you see garbled characters or the connection drops intermittently, try changing the flow control setting from "None" to "XON/XOFF". Conversely, if the connection hangs immediately upon opening, ensure that "Hardware" flow control is disabled, as many modern USB adapters do not support RTS/CTS lines properly.
For users who previously struggled with other command-line utilities, understanding the distinction between general file finding errors and specific connection configurations is vital. Just as one must carefully handle delete and prune in Linux Find Command Using 'delete' and 'prune' Gives Error scenarios to avoid data loss, precise parameter entry in serial tools prevents connection failures.
Frequently Asked Questions
Can I use PuTTY to connect via Wi-Fi?
No, PuTTY is primarily a terminal emulator for network protocols like SSH, Telnet, and raw TCP/UDP, or for local serial ports. It does not manage Wi-Fi networks or wireless authentication. You should use standard Linux networking tools like wpa_supplicant or NetworkManager to handle Wi-Fi connectivity before launching PuTTY.
Why does my serial connection show garbage characters?
Garbage characters almost always indicate a mismatch in baud rate or parity settings between your PuTTY configuration and the target device. Verify that the speed (e.g., 9600 vs 115200) matches exactly. Also, ensure that data bits and stop bits are identical on both ends, as even a single bit difference will corrupt the data stream.
Is plink available on all Linux distributions?
Yes, plink is included in the standard putty-tools or putty packages on most major Linux distributions. You can install it using your package manager, such as apt-get install putty-tools on Debian or Ubuntu, or yum install putty on CentOS. It is not installed by default on minimal server installations.
How do I fix permission denied errors on /dev/ttyUSB0?
This error occurs because your user account lacks read/write access to the serial device. You can resolve this by adding your user to the dialout group using the command sudo usermod -aG dialout $USER. After running this command, log out and log back in for the changes to take effect.
Can I use PuTTY to monitor disk usage discrepancies?
PuTTY is a remote login tool and cannot analyze local file system statistics directly. If you suspect discrepancies between du and ls outputs, you should run those commands locally or via an SSH session to inspect inode usage and hidden files, as discussed in Discrepancy in Disk Usage Between du and ls Commands in Linux: Possible Explanations.