Plink - Command Line SSH Client

The command-line interface to PuTTY for automated SSH connections and scripting

What is Plink?

Plink (PuTTY Link) is a command-line connection tool similar to UNIX ssh. It is mostly used for automated operations, such as making SSH connections as part of a batch file or script.

Plink is part of the PuTTY suite and provides the same functionality as the graphical PuTTY client, but in a command-line interface suitable for scripting and automation.

Key Features:

  • • Command-line SSH, Telnet, and raw connections
  • • Support for SSH-1, SSH-2 protocols
  • • Public key authentication
  • • Local and remote port forwarding
  • • Batch file and script automation
  • • Compatible with PuTTY session configurations

Basic Usage

Simple SSH Connection

plink username@hostname

Execute Remote Command

plink username@hostname "ls -la"

Using Saved Session

plink session_name

With Private Key Authentication

plink -i private_key.ppk username@hostname

Common Command Line Options

OptionDescription
-sshForce SSH protocol
-telnetForce Telnet protocol
-P portSpecify port number
-l usernameSpecify username
-pw passwordSpecify password
-i keyfileSpecify private key file
-L port:host:portLocal port forwarding
-R port:host:portRemote port forwarding
-batchDisable interactive prompts

Automation Examples

Batch File Example

@echo off
plink -batch -i mykey.ppk user@server "mkdir /tmp/backup"
plink -batch -i mykey.ppk user@server "tar -czf /tmp/backup/data.tar.gz /var/www"
echo Backup completed successfully

PowerShell Script Example

$servers = @("server1", "server2", "server3")
foreach ($server in $servers) {
    plink -batch -i mykey.ppk "user@$server" "uptime"
}

Troubleshooting

Host Key Verification

On first connection, Plink will ask to verify the host key. For automation, you can:

echo y | plink username@hostname

Connection Timeout

If connections timeout, try increasing the timeout value:

plink -batch -o ConnectTimeout=30 username@hostname

Exit Codes

Plink returns the exit code of the remote command, making it suitable for error handling in scripts.

System Requirements

  • • Windows XP or later
  • • No installation required
  • • Runs from command prompt
  • • Compatible with all Windows versions
;