bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Bash/Networking
Bash•Networking

Bash ssh Command - 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 user@example.com
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
user@example.com:~ $

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 user@example.com
user@example.com'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 user@example.com
user@example.com:~ $

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 user@example.com
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

ssh -C user@example.com
user@example.com's password:

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

ssh -X user@example.com
user@example.com's password:

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 user@example.com
user@example.com'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.

Previous

Bash wget Command - Non-Interactive Network Downloader

Next

Bash scp Command - Secure Copy

This chapter

Overview
6

Lessons

19m

Read time

1. Bash ping Command - Send Request to Network Hosts2. Bash curl Command - Transfer a URL3. Bash wget Command - Non-Interactive Network Downloader4. Bash ssh Command - OpenSSH SSH Client5. Bash scp Command - Secure Copy6. Bash rsync Command - Remote (and local) File-copying

On this page

Using the ssh CommandBasic UsageSSH OptionsOption: -p (Port)Example: Specify PortOption: -i (Identity File)Example: Use Private KeyOption: -v (Verbose Mode)Example: Verbose ModeOption: -C (Compression)Example: Enable CompressionOption: -X (X11 Forwarding)Example: X11 ForwardingOption: -o (Specify Options)Example: Specify OptionsTroubleshooting Common Issues