Plink Commands – PuTTY SSH Command-Line Client
Plink (plink.exe) is the non-interactive SSH client in the PuTTY suite for Windows. Where PuTTY opens an interactive terminal, plink putty enables scripted SSH connections, remote command execution, and automated deployments — making it the preferred tool for batch files, CI pipelines, and Git-over-SSH workflows.
Download Plink
Plink is part of the PuTTY suite. Download plink.exe directly from the official release page:
chiark.greenend.org.uk – plink.exe standalone download
Basic Plink Syntax
plink [options] [user@]host [command]Common Command-Line Switches
| Switch | Description |
|---|---|
-ssh | Force SSH protocol (recommended — explicitly prevents fallback to Telnet). |
-P port | Connect to a non-default port (default is 22). |
-l user | Specify the login username. |
-pw password | Provide password (insecure — avoid in scripts; use key auth instead). |
-i key.ppk | Authenticate using a specific PPK private key file. |
-batch | Non-interactive mode: abort with non-zero exit if user input is required. |
-t | Allocate a pseudo-terminal (TTY) on the remote host. |
-T | Disable TTY allocation (for non-interactive scripted commands). |
-m file.txt | Read commands to execute on the remote host from a local text file. |
-agent | Enable Pageant agent forwarding. |
-A | Enable SSH agent forwarding (same as -agent). |
-X | Enable X11 display forwarding. |
-v | Verbose mode — output diagnostic connection information. |
Running a Single Remote Command
# Run 'uptime' on the remote server via SSH
plink -ssh user@example.com uptime
# Run a command as root using sudo (TTY allocation required)
plink -ssh -t user@example.com "sudo systemctl restart nginx"Using -batch to Prevent Script Hangs
In automated environments, interactive prompts (e.g., host key confirmation dialogues) will cause a script to hang indefinitely. The -batch flag forces Plink to exit with a non-zero status code instead:
# Will fail (exit code 1) rather than hang if host key is not cached
plink -ssh -batch user@example.com "ls -la /var/log/"
# In batch scripts, check the exit code
plink -ssh -batch user@server.com df -h
if %ERRORLEVEL% NEQ 0 (
echo Connection or execution failed
exit /b 1
)plink user@host interactively once and accepting, or use PuTTY to save the session first.Execute a List of Commands with -m
Store commands in a local text file, one per line, and pass it to Plink:
# commands.txt
echo "Starting deployment"
cd /var/www/app
git pull origin main
systemctl restart app.service
echo "Deployment complete"# Execute all commands from the file
plink -ssh -batch user@example.com -m commands.txtUsing Plink with a PPK Private Key
# Authenticate with a specific PPK key file
plink -ssh -i "C:UsersYou.sshdeploy.ppk" deploy@example.com "systemctl status app"Alternatively, load the key into Pageant first. Plink will automatically use keys from Pageant without specifying the -i flag.
Using Plink as an SSH Transport for Git
Set the GIT_SSH environment variable to point Git to Plink. This allows Git operations over SSH on Windows using PuTTY's authentication:
# Set environment variable (PowerShell)
$env:GIT_SSH = "C: oolsputtyplink.exe"
# Or set permanently via System Properties > Environment Variables
# Variable name: GIT_SSH
# Variable value: C: oolsputtyplink.exe
# Now git clone/push/pull operations use Plink for SSH
git clone git@github.com:user/repo.gitPort Forwarding with Plink
# Local port forwarding: forward local port 3306 to MySQL on remote server
plink -ssh -L 3306:localhost:3306 user@example.com -N
# Dynamic SOCKS proxy on local port 1080
plink -ssh -D 1080 user@example.com -NPlink Exit Codes
| Exit Code | Meaning |
|---|---|
0 | Remote command completed successfully. |
1 | Connection failed, authentication error, or interactive prompt was refused in batch mode. |
Non-zero | The remote command exited with a non-zero status — check the remote process output. |