How to SFTP to port different than 22 (SFTP Custom port)

How to SFTP to port different than 22
How to SFTP to port different than 22

If you are looking to connect to an SFTP server the default port is 22, but what if the provided port details that you have is not 22, you will need to use -P option to provide the custom port details,

Example Connect to SFTP Custom Port:
# sftp -P 8020

( Password: 

Connected to


As you can see by using -P option followed by the port number you can connect to a specific port.

Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.