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

SwitchDescription
-sshForce SSH protocol (recommended — explicitly prevents fallback to Telnet).
-P portConnect to a non-default port (default is 22).
-l userSpecify the login username.
-pw passwordProvide password (insecure — avoid in scripts; use key auth instead).
-i key.ppkAuthenticate using a specific PPK private key file.
-batchNon-interactive mode: abort with non-zero exit if user input is required.
-tAllocate a pseudo-terminal (TTY) on the remote host.
-TDisable TTY allocation (for non-interactive scripted commands).
-m file.txtRead commands to execute on the remote host from a local text file.
-agentEnable Pageant agent forwarding.
-AEnable SSH agent forwarding (same as -agent).
-XEnable X11 display forwarding.
-vVerbose 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
)
First Connection: On the first connection to a new host, Plink will prompt to accept the server's host key — even in batch mode, this will abort with an error. Pre-add the host key by running 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.txt

Using 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.git
Tip: Load your GitHub or GitLab SSH key into Pageant before running Git commands. Plink will use the agent automatically, avoiding passphrase prompts in every git operation.

Port 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 -N

Plink Exit Codes

Exit CodeMeaning
0Remote command completed successfully.
1Connection failed, authentication error, or interactive prompt was refused in batch mode.
Non-zeroThe remote command exited with a non-zero status — check the remote process output.