SSH (Secure Shell) lets you securely connect to another computer over a network, usually to run commands on a remote Linux server. This guide walks you through the basics: connecting, running commands, transferring files, and using keys for passwordless logins. You’ll need a Linux machine with an SSH client (almost always preinstalled) and access to a remote server with SSH enabled.
What You’ll Need
- A Linux computer (local machine) with the
sshcommand available (check withwhich ssh). - A remote server or another Linux machine with SSH server running (usually
sshd). - The remote server’s IP address or hostname, a username, and either a password or an SSH key.
- Network access to the remote machine (port 22 must be reachable).
Step-by-Step
- Open a terminal. On most Linux distributions, press
Ctrl+Alt+Tor search for “Terminal” in the applications menu. - Check if SSH is installed. Run
ssh -V. If you see a version number, you’re good. If not, install it: on Debian/Ubuntu usesudo apt install openssh-client, on Fedora/RHEL usesudo dnf install openssh-clients. - Connect to the remote server. Use the basic syntax:
ssh username@hostname. For example,ssh alice@192.168.1.100. Replacealicewith your username on the remote machine and the IP with the server’s address. - Accept the host key (first time only). The first time you connect, you’ll see a warning about the host’s authenticity. Type
yesand press Enter. This stores the server’s key in~/.ssh/known_hosts. - Enter your password. When prompted, type your password (nothing will show as you type, that’s normal) and press Enter. You should now be logged in to the remote shell.
- Run commands remotely. Once connected, any command you type runs on the remote machine. For example,
whoamishows the remote user,lslists files in the remote directory. - Exit the session. Type
exitor pressCtrl+Dto return to your local terminal. - Run a single command without a full session. Use
ssh username@hostname 'command'. For example,ssh alice@192.168.1.100 'uptime'runsuptimeon the remote and shows the output locally, then disconnects. - Copy files with SCP. To copy a file from local to remote:
scp /path/to/local/file username@hostname:/path/on/remote. To copy from remote to local:scp username@hostname:/path/on/remote/file /path/to/local/. - Set up SSH key authentication (recommended). Generate a key pair on your local machine:
ssh-keygen -t ed25519. Press Enter to accept the default location (~/.ssh/id_ed25519) and optionally set a passphrase. Then copy the public key to the server:ssh-copy-id username@hostname. This adds your public key to the server’s~/.ssh/authorized_keysfile. - Test passwordless login. After copying the key, try
ssh username@hostname. It should log you in without asking for a password (if you set a passphrase, it will ask for that instead).
Common Mistakes
- Typing your password while it’s not asked. Wait for the prompt. If you type before the prompt, characters may appear in the terminal or be ignored.
- Using the wrong username. The username must be a valid account on the remote machine. If you’re not sure, try the default like
ubuntufor cloud servers orrootfor some VPS. - Forgetting the port. If the server uses a non-default port, you must specify it with
-p(lowercase) for SSH, e.g.,ssh -p 2222 user@host. For SCP, use-P(uppercase). - Ignoring the host key warning. If you see a warning that the host key has changed, it could be a security issue (man-in-the-middle) or the server was reinstalled. Don’t blindly accept it; verify with the server admin.
- Using a relative path with SCP. Always use absolute paths or ensure the relative path is correct from the current directory. For remote paths, a relative path is relative to the remote user’s home directory.
Tips
- Create an SSH config file. In
~/.ssh/config, you can define hosts. For example:Host myserver HostName 192.168.1.100 User alice Port 2222Then just type
ssh myserver. - Use
-vfor verbose output. If something goes wrong,ssh -v user@hostshows detailed debug info that helps diagnose issues. - Keep your private key safe. Never share your private key (
~/.ssh/id_ed25519). Add a passphrase to protect it if your laptop is stolen. - Use
ssh-agentto avoid typing passphrases. Add your key once withssh-addand it will be used automatically for the session. - For file transfers, consider
rsyncover SSH. It’s more efficient for large or incremental transfers:rsync -avz /local/dir user@host:/remote/dir.
Troubleshooting
- Connection refused. The SSH server isn’t running or the port is blocked. Check with
sudo systemctl status sshd(on the remote, if you have console access) or trytelnet host 22to see if the port is open. - Permission denied (publickey,password). Your password or key is wrong, or the server doesn’t allow password auth. Try
ssh -vto see which authentication methods are offered. If using keys, ensure the public key is in the correct~/.ssh/authorized_keyson the remote and permissions are correct (chmod 700 ~/.ssh, chmod 600 ~/.ssh/authorized_keys). - Host key verification failed. The server’s key changed. If you trust the server, remove the old entry with
ssh-keygen -R hostnameand reconnect. - Connection timed out. Network issue or firewall blocking port 22. Check your local network and any cloud security groups. Try pinging the host to see if it’s reachable.
- Terminal freezes after login. This can happen with a broken shell profile. Try connecting with
ssh user@host /bin/bashto bypass the default shell.
Frequently Asked Questions
What is the default SSH port?
Port 22. If the server uses a different port, you must specify it with -p.
Can I use SSH on Windows?
Yes, Windows 10 and 11 have OpenSSH client built-in. You can use the same commands in PowerShell or CMD.
How do I copy files from remote to local?
Use scp user@host:/path/to/remote/file /local/destination.
What is the difference between SSH and SCP?
SSH is for interactive login and running commands; SCP is for copying files over the SSH protocol.
How do I change my SSH password?
You can’t change it via SSH directly. You need to use the passwd command on the remote machine after logging in.
Is SSH safe to use over the internet?
Yes, SSH encrypts all traffic. Just use strong passwords or keys, and avoid using the default root account with a weak password.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Change Google Text-to-Speech Voice on Android
- How to Adjust Volume Levels on a Windows PC
- Reset Chrome Sync to Fix Problems
- Fix Mouse Not Working in Windows 11
- Fix Windows Defender Failed to Initialize Error
- How to Hide or Unhide NFTs on OpenSea Profile