DEV Community

dpm_bush
dpm_bush

Posted on Originally published at sshflow.com

What Happens When You SSH Into a Server?

When you “SSH into” a server, your computer uses the SSH protocol to connect to another computer over a network. If the connection is accepted and you authenticate successfully, you can usually interact with a shell running on the remote machine.

The phrase is informal, but the distinction matters: SSH is the protocol, ssh is a client command, and the shell is the command interpreter you may use after connecting.

A connection in one command

A typical SSH command looks like this:

ssh username@server.example.com
Enter fullscreen mode Exit fullscreen mode

Replace username with an account on the remote computer and server.example.com with its hostname or address. The command starts a connection attempt; it doesn't create an account or grant access by itself.

At a high level, the process is:

  1. Your local SSH client contacts the remote host.
  2. The client and host establish an encrypted connection.
  3. The host verifies that you’re allowed to log in, using an authentication method configured for the server.
  4. If the connection requests an interactive login, the server provides a shell session.

Authentication might use a password, an SSH key, or another method configured for that host. You need valid authorization whichever method is used.

Where do commands run?

After an interactive login succeeds, the prompt you see is usually a shell on the remote computer. For example, if you run a command to list files in that session, it lists files on the server—not files on your laptop.

Your local terminal is where you type and view the results. The remote machine runs the commands, subject to the permissions of the account you logged in as.

That’s why it’s worth checking where you are before running commands that change files or services. A prompt from a remote host can look similar to a local one. You can check the current host with:

hostname
Enter fullscreen mode Exit fullscreen mode

The command runs wherever the current shell is running. In an SSH session, that’s normally the remote machine.

SSH, terminal, and shell aren’t the same thing

These terms often appear together, but they refer to different parts of the experience:

  • SSH is the protocol that provides the secure connection.
  • SSH client is the program on your computer that starts the connection. The ssh command is a common client.
  • Terminal is the local application where you enter text and read output.
  • Shell interprets commands. With an interactive SSH login, it commonly runs on the remote computer.

A standard SSH shell session is also different from a remote desktop. SSH normally gives you a text-based command-line session, not a graphical desktop interface.

Not every SSH connection opens a shell

An interactive shell is a common use of SSH, but it isn’t the only one. SSH can also be used to run a command remotely or transfer files securely. In those cases, the connection may be used for a specific task rather than opening a shell prompt.

So “SSH into a server” usually means logging in to use its command line, but the underlying protocol can carry other kinds of work too.

What does “secure” mean here?

SSH encrypts communication between the client and the remote host, helping prevent others on the network from reading or modifying the session in transit. It also involves authentication: the client verifies the host it is reaching, and the server checks whether the user is permitted to connect.

Encryption doesn’t make the remote computer inherently trustworthy or invulnerable. It also doesn’t bypass account permissions. Treat the host identity and the credentials or keys you use as important parts of the connection.

If the connection doesn’t work

A few basic checks can help narrow down the problem:

  • Confirm the username and hostname or address are correct.
  • Check that you’re using an account that is allowed to connect to that host.
  • Read the client’s error message; it may indicate whether the problem is reaching the host or authenticating.
  • If you’re unsure what a command will affect, first confirm whether your shell is local or remote.

The essential idea is simple: SSH is the secure connection mechanism, while the shell is one way to use the computer on the other end. When you run commands in a remote SSH shell, they run on that remote machine with the access granted to your account.

I originally published a more detailed version of this guide on the SSHFlow blog.

I'm also building SSHFlow — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.

Top comments (0)