The command-line interface to PuTTY for automated SSH connections and scripting
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.
plink username@hostname
plink username@hostname "ls -la"
plink session_name
plink -i private_key.ppk username@hostname
Option | Description |
---|---|
-ssh | Force SSH protocol |
-telnet | Force Telnet protocol |
-P port | Specify port number |
-l username | Specify username |
-pw password | Specify password |
-i keyfile | Specify private key file |
-L port:host:port | Local port forwarding |
-R port:host:port | Remote port forwarding |
-batch | Disable interactive prompts |
@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
$servers = @("server1", "server2", "server3")
foreach ($server in $servers) {
plink -batch -i mykey.ppk "user@$server" "uptime"
}
On first connection, Plink will ask to verify the host key. For automation, you can:
echo y | plink username@hostname
If connections timeout, try increasing the timeout value:
plink -batch -o ConnectTimeout=30 username@hostname
Plink returns the exit code of the remote command, making it suitable for error handling in scripts.