Network security

How to SSH Into a Server: Windows, Mac and Linux in 5 Steps

SSH is the standard way to manage a remote server from your own computer. This guide shows the exact commands for Windows, macOS and Linux.

Cysoro Security TeamPublished · 7 min read
NETWORK SECURITYSSHinto a serverEncrypted remote login, step by step$ ssh user@hostfingerprint: SHA256…Welcome to Ubuntu22
Quick answer

To SSH into a server, open a terminal and run ssh username@server-address, accept the server host key the first time, then enter your password or unlock your SSH key. Windows 10 and 11, macOS and most Linux systems include an OpenSSH client, so no extra software is needed for a basic connection.

Key takeaways

  • The basic command is ssh username@server-address, and SSH uses TCP port 22 by default.
  • Ed25519 key login is safer than a password and stops brute-force login attempts.
  • Always verify the host key fingerprint the first time you connect to a new server.

SSH, or Secure Shell, is how you manage a remote server from your own computer. You type commands locally, they run on the server, and everything travels over an encrypted connection. This guide covers the exact steps on Windows, macOS and Linux.

What is SSH and how does it work?

SSH is an encrypted network protocol that gives you a secure command-line session on a remote computer. It replaces older tools such as Telnet, which sent passwords in plain text.

When you connect, the client and server agree on encryption, the server proves its identity with a host key, and you prove yours with a password or a private key. After that, your keystrokes and the server replies are encrypted. Microsoft describes OpenSSH as a connectivity tool that encrypts all traffic to eliminate eavesdropping and connection hijacking, in its OpenSSH guide for Windows.

SSH runs on TCP port 22 by default. The server program is called sshd, and the client program is called ssh. Most Linux servers already run sshd; your laptop only needs the client.

What do you need before you SSH into a server?

You need four things: the server address, a username, a way to prove who you are, and network access to the server. Without any one of these, the connection will fail.

  • Server address: an IP address such as 203.0.113.10 or a hostname such as server.example.com.
  • Username: often root, ubuntu, ec2-user or a named account your administrator created.
  • Credential: a password, or preferably an SSH key pair.
  • Network path: the server must be reachable, and port 22 (or its custom port) must be open.

If you are connecting to a cloud server, these details are usually in the welcome email or the cloud console. If it is a work server, ask your administrator for the address, username and port.

Before you connect: the four things you need1. AddressIP or hostname203.0.113.102. Usernameroot, ubuntu,ec2-user…3. Credentialpassword orEd25519 key4. Network pathport 22 open,VPN if neededMissing one of these? Fix that first — the ssh command cannot help.
The four things every SSH connection needs. Illustration by Cysoro.

How do you SSH into a server from Linux or macOS?

Open a terminal and run ssh username@server-address, replacing the username and address with your own. On macOS use Terminal; on Linux use any terminal app.

For example, to log in as ubuntu to a server at 203.0.113.10, run:

ssh ubuntu@203.0.113.10

The first time you connect, SSH shows the server host key fingerprint and asks whether to continue. Type yes only if you trust this server and the fingerprint matches the one your host or administrator gave you. The fingerprint is then saved in ~/.ssh/known_hosts.

Next, enter your password. Nothing appears on screen as you type, not even dots. That is normal. Press Enter and you should see the server prompt. Check that SSH is installed first with ssh -V; if it is missing on Linux, install it with your package manager, for example sudo apt install openssh-client on Ubuntu.

How do you SSH into a server from Windows?

Open PowerShell or Windows Terminal and run the same command: ssh username@server-address. Windows 10 build 1809 and later, and Windows 11, include the OpenSSH client.

First check it is there by running ssh -V in PowerShell. If the command is not found, install it under Settings, then Apps, then Optional features, by adding OpenSSH Client. Microsoft documents this as an optional feature in its OpenSSH installation guide.

PuTTY is still a valid alternative if you prefer a graphical tool or need saved sessions. Enter the server address, set the port to 22, click Open, accept the host key and log in. For most people, the built-in client is simpler because the commands match macOS and Linux exactly.

How do you SSH into a server on a different port?

Add -p followed by the port number, for example ssh -p 2222 user@203.0.113.10. Some administrators move SSH off port 22 to reduce automated login attempts.

If a connection hangs or is refused on port 22, ask your administrator whether the server uses a custom port before changing anything else. A refused connection on the wrong port looks the same as a server that is down.

You can also write the username as an option: ssh -l alex server.example.com. The -p flag works on Windows, macOS and Linux in exactly the same way.

How do you set up SSH key login?

Key login replaces your password with a pair of files: a private key that stays on your laptop and a public key that goes on the server. It is safer because a key cannot be guessed like a password.

Step 1: create a key pair on your own computer. Run this command on Windows, macOS or Linux:

ssh-keygen -t ed25519 -C "my-laptop"

Accept the default location, then choose a strong passphrase. The private key is saved as ~/.ssh/id_ed25519 and the public key as ~/.ssh/id_ed25519.pub. Never share the private key file.

Step 2: copy the public key to the server. On Linux and macOS, run ssh-copy-id user@server-address and enter your password one last time. On Windows, where ssh-copy-id is not included, run this in PowerShell:

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Step 3: test the key login with ssh user@server. It should ask for your key passphrase, not your account password. Only after that works should you consider disabling password login on the server.

Key login in three steps1. Generatessh-keygen -t ed25519on your laptop2. Copy public keyssh-copy-id user@serveror append to authorized_keys3. Test itssh user@servershould ask for passphraseOnly disable password login after key login works.
Ed25519 key login: generate, copy the public half, test. Illustration by Cysoro.

How do you save SSH connection details?

Create a file called config in your .ssh folder, with no file extension, and add one block per server. After that you can connect with a short name instead of the full address.

For example, this block lets you run ssh web-prod instead of typing the address, user and port every time:

Host web-prod
HostName 203.0.113.10
User ubuntu
Port 2222
IdentityFile ~/.ssh/id_ed25519

On Windows the file lives at %USERPROFILE%\.ssh\config; on macOS and Linux it is ~/.ssh/config. Keep its permissions tight so other users cannot read it.

You can also connect through a jump host in one command with ssh -J user@bastion.example.com user@10.20.1.15. That is useful when the target server is only reachable from inside a private network.

What else can you do once you are connected?

Once logged in, you have the server command line. You can also run a single command without staying logged in, copy files, and forward ports for secure access.

Run one command and exit with ssh user@server "uptime". Copy a file to the server with scp file.txt user@server:/home/user/. Copy a file back with scp user@server:/var/log/app.log .

To keep a session alive through an idle network, add ServerAliveInterval 60 to your SSH config. To disconnect, type exit or press Ctrl+D.

Why will SSH not connect? Common errors and fixes

Most SSH failures fall into four groups: the client cannot reach the server, the server rejects the login, the host key changed, or the key file has wrong permissions. The error message usually tells you which one.

ErrorLikely causeFix
Connection timed outWrong address, server down, or firewall blocking the portCheck the address and port; check the server is running
Connection refusedNo SSH server listening on that portStart sshd; check the port in sshd_config
Permission denied (publickey,password)Wrong user, key or passwordCheck authorized_keys and run ssh -v for detail
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGEDHost key changed or a different server now uses the addressVerify with the administrator; then ssh-keygen -R server
Permissions are too open (private key)Key file readable by othersRun chmod 600 ~/.ssh/id_ed25519
ssh: command not foundOpenSSH client not installedInstall it via Optional Features on Windows or your package manager

Run ssh -v user@server for verbose output when you are stuck. It shows each step, including which keys were offered and why each was accepted or rejected.

Never ignore a changed host keySSH warns you if a server host key changes. It can mean the server was rebuilt, but it can also mean someone is intercepting the connection. Check with your administrator before you remove the old key.

How do you secure SSH after you can log in?

Once key login works, harden the server so password guessing stops working. These changes belong in /etc/ssh/sshd_config on the server, followed by a restart of the SSH service.

  • Disable password login: set PasswordAuthentication no and PermitRootLogin prohibit-password.
  • Use Ed25519 keys only: Mozilla OpenSSH guidance recommends modern key types and keeping OpenSSH updated.
  • Limit who can log in: use AllowUsers with named accounts only.
  • Keep OpenSSH updated: apply operating system updates promptly.
  • Protect the private key: use a passphrase, store it only on devices you control, and never commit it to a code repository.

For a wider check of your own setup, our guide to securing your Wi-Fi covers the home network side.

The small business cybersecurity checklist covers server and account basics together.

The bottom line

SSH into a server with ssh username@server-address, verify the host key the first time, and move to Ed25519 key login as soon as you can. Keys are both easier day to day and far harder for attackers to guess than passwords.

If a connection fails, read the error, check the address and port, then run ssh -v before changing settings at random. You can check what your connection looks like from the outside with our free what-is-my-IP tool.

Frequently asked questions

How do I SSH into a server for the first time?

Open a terminal, run ssh username@server-address, type yes when asked about the host key, then enter your password or key passphrase. The fingerprint is saved in ~/.ssh/known_hosts so you are not asked again for that server.

What port does SSH use?

SSH uses TCP port 22 by default. If your server listens on another port, add -p and the port number, for example ssh -p 2222 user@203.0.113.10. The firewall must allow that port.

How do I SSH without a password?

Create an Ed25519 key pair with ssh-keygen -t ed25519, then copy the public key to the server with ssh-copy-id user@server. After that, SSH uses the key instead of a password.

Why do I get Permission denied (publickey,password)?

It means the server rejected both methods. Check the username, check that your key is in the server's ~/.ssh/authorized_keys file, and check file permissions. Run ssh -v user@server to see which keys were offered.

Why do I get Connection refused when I SSH?

Connection refused usually means no SSH server is listening on that address and port, or a firewall is blocking it. Check that sshd is running on the server and that port 22, or your custom port, is open.

Is SSH safe to use over public Wi-Fi?

Yes, SSH encrypts the whole session, including your password and everything you type. That is its main purpose. Still use key login, keep the server updated, and never accept a changed host key without checking why it changed.

How do I disconnect from an SSH session?

Type exit and press Enter, or press Ctrl+D. If a session hangs, press Enter, then type ~. to force the client to close.

Can I SSH from Windows without PuTTY?

Yes. Windows 10 build 1809 and later, and Windows 11, include the OpenSSH client. Open PowerShell or Windows Terminal and run the same ssh commands as on macOS and Linux.

Sources

  1. Microsoft Learn — Get started with OpenSSH Server for Windows
  2. Kali Linux Documentation — Installing Kali Linux
  3. Mozilla Wiki — Security/Guidelines/OpenSSH
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against Microsoft Learn OpenSSH documentation, the OpenSSH security guidance from Mozilla, and standard OpenSSH client behaviour on Windows, macOS and Linux.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free