Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH

Bash ssh - OpenSSH SSH Client

Using the ssh Command

The ssh command is used to connect to a remote machine securely.


Basic Usage

To connect to a remote host, use ssh user@hostname:

Example

ssh [email protected]
Linux raspberrypi 6.6.74+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.74-1+rpt1 (2025-01-27) aarch64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Apr 10 13:09:32 2025 from 45.14.193.140
[email protected]:~ $

SSH Options

Here are some common options you can use with the ssh command:

  • -p - Specify the port
  • -i - Use a private key file
  • -v - Enable verbose mode
  • -C - Enable compression
  • -X - Enable X11 forwarding
  • -o - Specify options directly on the command line

Option: -p (Port)

The -p option lets you specify the port to connect to on the remote host.

By default, SSH uses port 22.

Example: Specify Port

ssh -p 2222 [email protected]
[email protected]'s password:

Option: -i (Identity File)

The -i option allows you to specify a private key file for authentication.

This is useful when you have a specific key for a server.

Example: Use Private Key

ssh -i /path/to/private_key [email protected]
[email protected]:~ $

Option: -v (Verbose Mode)

The -v option enables verbose mode, which provides detailed information about the SSH connection process.

This is helpful for debugging.

Example: Verbose Mode

ssh -v [email protected]
OpenSSH_9.6p1, OpenSSL 3.2.1 30 Jan 2024
debug1: Reading configuration data /home/users/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to example.com port 22.
debug1: Connection established.
.....

Option: -C (Compression)

The -C option enables compression, which can speed up data transfer by reducing the amount of data sent over the network.

Example: Enable Compression


Option: -X (X11 Forwarding)

The -X option allows X11 forwarding, enabling you to run graphical applications on the remote server and display them locally.

Example: X11 Forwarding


Option: -o (Specify Options)

The -o option allows you to specify SSH options directly on the command line.

This is useful for overriding configuration settings.

Example: Specify Options

ssh -o StrictHostKeyChecking=no [email protected]
[email protected]'s password:

Troubleshooting Common Issues

Common issues like "Connection Refused" or "Host Key Verification Failed" can occur. Here are some steps to troubleshoot these problems:

  • Connection Refused: Ensure the SSH service is running on the remote server and the correct port is being used. Check firewall settings to make sure they are not blocking the connection.
  • Host Key Verification Failed: This happens when the server's host key changes. Verify the server's identity and update the known_hosts file by removing the old key entry.
  • Permission Denied: Check permissions and username. Check the server's SSH configuration for restrictions.
  • Timeouts: Check network connectivity and server responsiveness. Adjust the SSH timeout settings if necessary.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.