DEV Community

mich0w0h
mich0w0h

Posted on

SSH: Connect to a server with a port number and a username

Every time I try to SSH I forget how to do it.

That's why I decided to take notes with this post.

What I want to achieve

  • connect a server on a certain port using SSH.
  • username and password are given.

Ask man

Just run the command in the terminal.

$ man ssh
Enter fullscreen mode Exit fullscreen mode

The output is here;

NAME
     ssh – OpenSSH remote login client

SYNOPSIS
     ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char]
         [-F configfile] [-I pkcs11] [-i identity_file] [-J destination] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option]
         [-P tag] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] destination
         [command [argument ...]]
Enter fullscreen mode Exit fullscreen mode

This is not enough to specify the username.

To log in with a particular username the command would be this;

$ ssh username@hostname
Enter fullscreen mode Exit fullscreen mode

There it is!

Connect a server using SSH

Input the following command in the terminal.

$ ssh -p port username@hostname
Enter fullscreen mode Exit fullscreen mode

The connection would be established after entering the password as the prompt asks.

References

Top comments (0)