Home » Blog » How to Connect to SSH Using Linux/Ubuntu Desktop

How to Connect to SSH Using Linux/Ubuntu Desktop

by Salman Chawhan
0 comments

SSH (Secure Shell) is a secure protocol for accessing remote servers. It allows administrators to control and manage servers remotely. In this guide, we’ll explore how to connect to SSH from a Linux or Ubuntu desktop in three scenarios:

  1. Without specifying an SSH port (default port 22).
  2. With a custom SSH port.
  3. Using a custom port along with .ppk or .pem files.
  4. Steps to Save SSH Connections in the SSH Config File

1. Connect to SSH Without Specifying a Port

The default SSH port is 22, so if the server uses the default port, no additional configuration is needed.

Steps to Connect

  1. Open the Terminal on your Linux/Ubuntu desktop.
  2. Use the following command:
     
    ssh username@server_ip
    Replace username with the SSH username and server_ip with the IP address of the remote server.

Example:

ssh root@192.168.1.100

What Happens:

  • The SSH client connects to port 22 by default.
  • You’ll be prompted to enter the password for the user.

2. Connect to SSH with a Custom Port

If the server is configured to use a non-default SSH port, you need to specify it in the command.

Steps to Connect

  1. Determine the custom port number configured on the server (e.g., 2222).
  2. Use the -p option in the SSH command to specify the port:
     
    ssh username@server_ip -p port_number

Example:

ssh root@192.168.1.100 -p 2222

What Happens:

  • The SSH client connects to the specified custom port.
  • Enter the password when prompted.

3. Connect to SSH with a Custom Port Using .ppk or .pem Files

Private keys (.ppk or .pem) are often used for passwordless SSH authentication.

For .pem File:

  1. Ensure the .pem file is on your local system and has the correct permissions:

  2. chmod 600 keyfile.pem

  3. Use the -i option with the SSH command to specify the private key:

  4. ssh -i /path/to/keyfile.pem username@server_ip -p port_number

Example:

ssh -i ~/keys/TokyoKey.pem ubuntu@192.168.1.100 -p 2222

For .ppk File:

Linux SSH clients typically use .pem files. To use a .ppk file, convert it to .pem format using

puttygen:

  1. Install putty-tools if not already installed:
     
    sudo apt install putty-tools
  2. Convert the .ppk file to .pem:
     
    puttygen keyfile.ppk -O private-openssh -o keyfile.pem
  3. Use the converted .pem file as shown in the previous example.

4. Steps to Save SSH Connections in the SSH Config File

  1. Locate or Create the SSH Config File

    • Open a terminal and navigate to the .ssh directory in your home folder:
       
      cd ~/.ssh
    • If the config file doesn’t exist, create it:
       
      touch config
  2. Edit the Config File

    • Open the config file in a text editor, such as nano or vim:
       
      nano config
  3. Add SSH Connection Details Add the details of your SSH connection to the file. Below are examples for each scenario:

    Example 1: Default SSH Port

     
    Host myserver HostName 192.168.1.100 User root

    Example 2: Custom SSH Port

     
    Host mycustomserver HostName 192.168.1.100 User root Port 2222

    Example 3: Custom Port with .pem or .ppk File

     
    Host mykeyserver HostName 192.168.1.100 User ubuntu Port 2222 IdentityFile ~/keys/TokyoKey.pem
  4. Save and Exit

    • For nano, press Ctrl + O, then Enter to save, and Ctrl + X to exit.
  5. Connect Using the Shortcut

    • Use the Host name defined in the config file as a shortcut:
       
      ssh myserver
      or
       
      ssh mycustomserver
      or
       
      ssh mykeyserver

Benefits of Using the SSH Config File

  • Shortcuts: No need to remember IP addresses, usernames, ports, or key file paths.
  • Automation: Simplifies scripts or cron jobs that require SSH connections.
  • Organization: Manage multiple server connections easily in one file.

Advanced Tip: Test Your Connection

To verify that your configuration works, use the -v flag (verbose mode):

ssh -v myserver

Now, you can connect to your servers effortlessly with saved configurations!

You may also like

Leave a Comment

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00