DEV Community

Sospeter Mong'are
Sospeter Mong'are

Posted on

How to SSH into a Server Using IP Address, Username, and Password

Introduction

Secure Shell (SSH) is a protocol used to remotely access servers over an encrypted connection. If you have the server IP address, username, and password, you can use SSH to log in and manage the server securely. This article explains how to establish an SSH connection from various environments.


1. SSH via the Command Line (Linux, Mac, or WSL)

On Linux, macOS, or Windows Subsystem for Linux (WSL), you can use the built-in ssh command to connect to a remote server.

Command Syntax

ssh username@server_ip
Enter fullscreen mode Exit fullscreen mode
  • Replace username with your actual server login name.
  • Replace server_ip with the server's IP address.

Example

ssh sos@192.168.1.100
Enter fullscreen mode Exit fullscreen mode

Steps

  1. Open a terminal (Command Line, Terminal, or WSL).
  2. Run the ssh command with the username and server IP.
  3. If this is your first time connecting, you may see the following prompt:
   Are you sure you want to continue connecting (yes/no)?
Enter fullscreen mode Exit fullscreen mode

Type yes and press Enter.

  1. You will then be prompted for the server password:
   sos@192.168.1.100's password:
Enter fullscreen mode Exit fullscreen mode
  1. Enter the password for the user. If the credentials are correct, you will gain access to the server.

2. SSH with Automatic Password Input (Using sshpass)

If you want to supply the password non-interactively, you can use the sshpass utility. This is useful for automation, but it is less secure as passwords are exposed in plain text.

Install sshpass

  • On Ubuntu/Debian-based systems:
   sudo apt-get install sshpass
Enter fullscreen mode Exit fullscreen mode
  • On RedHat/CentOS-based systems:
   sudo yum install sshpass
Enter fullscreen mode Exit fullscreen mode

Command Syntax

sshpass -p "your_password" ssh username@server_ip
Enter fullscreen mode Exit fullscreen mode

Example

sshpass -p "mypassword123" ssh sos@192.168.1.100
Enter fullscreen mode Exit fullscreen mode

This command connects to the server without prompting for a password.

Security Warning: Avoid using sshpass in production environments, as it exposes the password in plain text. Consider using SSH keys for secure and automated logins.


3. SSH Using PuTTY (Windows)

For Windows users, PuTTY is a popular graphical SSH client that simplifies the process of connecting to servers.

Steps to Use PuTTY

  1. Download PuTTY:

    • Visit the official PuTTY website: https://www.putty.org/.
    • Download and install the appropriate version for your system.
  2. Open PuTTY:

    • Launch the PuTTY application.
    • In the "Host Name (or IP address)" field, enter the server IP.
    • Set the Port to 22 (default SSH port).
    • Select SSH as the connection type.
  3. Login:

    • Click Open to initiate the connection.
    • When prompted, enter the username and password to log in.
  4. Trust the Server:

    • If it's your first connection, PuTTY will ask you to trust the server's fingerprint. Click Yes to proceed.

4. Troubleshooting Common Issues

If you encounter problems connecting via SSH, consider the following troubleshooting tips:

  1. Connection Timeout:

    • Ensure the server is reachable over the network.
    • Verify that the SSH service (sshd) is running on the server.
    • Confirm that the server firewall allows traffic on port 22.
  2. Connection Refused:

    • Verify that SSH is installed and enabled on the server.
    • Check that the SSH port is set to 22 (or a custom port, if configured).
  3. Password Authentication Failure:

    • Double-check the username and password.
    • If password authentication is disabled, the server may require SSH key-based authentication.
  4. Host Key Verification Failed:

    • This happens if the server's key changes. Remove the old key by running:
     ssh-keygen -R server_ip
    

5. Enhancing Security with SSH Keys

Using passwords for SSH can be insecure and cumbersome. For better security and convenience, consider using SSH keys instead of passwords. With SSH keys:

  • Passwords are no longer required for login.
  • Authentication is faster and more secure.

To set up SSH keys:

  1. Generate a key pair with:
   ssh-keygen -t rsa -b 4096
Enter fullscreen mode Exit fullscreen mode
  1. Copy the public key to the server:
   ssh-copy-id username@server_ip
Enter fullscreen mode Exit fullscreen mode
  1. Connect without a password:
   ssh username@server_ip
Enter fullscreen mode Exit fullscreen mode

Let me know if you'd like a detailed guide on setting up SSH keys!


Conclusion

SSH is a powerful tool for managing servers remotely. By using the ssh command, sshpass, or tools like PuTTY, you can easily connect to servers with an IP, username, and password. However, for enhanced security, transitioning to SSH keys is highly recommended. If you encounter any issues, double-check network connectivity, server configuration, and credentials.

Top comments (0)