How to Specify Port Number in PuTTY Command Line for SSH Connections on Windows


1 views

When connecting via SSH using PuTTY from Windows command line, the basic syntax is:

cmd://"C:\Program Files\PuTTY\putty.exe" -ssh username@hostname

This defaults to port 22, the standard SSH port. However, many servers use non-standard ports for security reasons.

The proper way to specify a port in the command line is using the -P flag (uppercase P), not by appending it to the hostname as you might do with OpenSSH:

cmd://"C:\Program Files\PuTTY\putty.exe" -ssh username@hostname -P portnumber

For example, to connect to example.com on port 2222:

cmd://"C:\Program Files\PuTTY\putty.exe" -ssh admin@example.com -P 2222

Several incorrect approaches that won't work:

# Wrong: Using colon syntax (OpenSSH style)
cmd://"C:\Program Files\PuTTY\putty.exe" -ssh user@host:port

# Wrong: Using lowercase -p
cmd://"C:\Program Files\PuTTY\putty.exe" -ssh user@host -p 2222

# Wrong: Putting port before host
cmd://"C:\Program Files\PuTTY\putty.exe" -ssh -P 2222 user@host

Combine port specification with other common PuTTY options:

# With private key authentication
cmd://"C:\Program Files\PuTTY\putty.exe" -ssh -P 2222 -i "C:\keys\private.ppk" user@host

# With saved session
cmd://"C:\Program Files\PuTTY\putty.exe" -load "MySession" -P 2222

# With specific SSH protocol version
cmd://"C:\Program Files\PuTTY\putty.exe" -ssh -2 -P 2222 user@host

For scripting purposes, you might prefer Plink (PuTTY Link):

cmd://"C:\Program Files\PuTTY\plink.exe" -P 2222 user@host command_to_execute

Remember that unlike the PuTTY GUI, command line options are case-sensitive. Always use -P (uppercase) for port specification.


When working with PuTTY through Windows command line, many developers encounter port specification challenges. The default SSH port (22) works seamlessly with basic commands, but custom ports require specific syntax handling.

The proper way to specify a non-standard port combines the -P flag with the port number:

cmd://\"C:\\Program Files\\PuTTY\\putty.exe\" -ssh root@xxx.xx.xxx.xx -P xxxx

Three frequent mistakes developers make:

  1. Using colon syntax (host:port) which works in GUI but fails in CLI
  2. Omitting space after -P parameter
  3. Confusing uppercase -P with lowercase -p (used for serial connections)

For connecting to server 192.168.1.100 on port 2222:

cmd://\"C:\\Program Files\\PuTTY\\putty.exe\" -ssh admin@192.168.1.100 -P 2222

For AWS EC2 instance with custom port 4567:

cmd://\"C:\\Program Files\\PuTTY\\putty.exe\" -ssh ec2-user@54.210.33.101 -P 4567

For frequent connections, create named sessions with ports:

cmd://\"C:\\Program Files\\PuTTY\\putty.exe\" -load \"Production-Server-2222\"

Configure the port in PuTTY's Session configuration before saving.

  • Verify port accessibility: telnet xxx.xx.xxx.xx xxxx
  • Check firewall rules on both client and server
  • Validate SSH service is listening on specified port

For scripted environments, consider PuTTY's command-line cousin:

plink.exe -ssh root@xxx.xx.xxx.xx -P xxxx -pw password