{"id":9141,"date":"2026-04-07T18:25:41","date_gmt":"2026-04-07T18:25:41","guid":{"rendered":"https:\/\/commandlinux.com\/?p=9141"},"modified":"2026-04-17T20:08:33","modified_gmt":"2026-04-17T20:08:33","slug":"ssh-login","status":"publish","type":"post","link":"https:\/\/commandlinux.com\/qa\/ssh-login\/","title":{"rendered":"How To Use The SSH Login Command"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n<link rel=\"preconnect\" href=\"https:\/\/fonts.googleapis.com\">\n<link href=\"https:\/\/fonts.googleapis.com\/css2?family=Lora:ital,wght@0,400;0,600;1,400&#038;family=JetBrains+Mono:wght@400;500&#038;family=DM+Sans:wght@400;500;600&#038;display=swap\" rel=\"stylesheet\">\n<style>\n\n.ssh-login-container a {\n    color: #1a56db;\n    text-decoration: none;\n    border-bottom: 1px solid transparent;\n    transition: border-color 0.2s;\n  }\n.ssh-login-container  a:hover { border-bottom-color: #1a56db; }\n\n  code {\n    font-family: 'JetBrains Mono', monospace;\n    font-size: 0.84em;\n    background: #f4f4f5;\n    padding: 0.15em 0.4em;\n    border-radius: 4px;\n    color: #c7254e;\n  }\n\n  pre {\n    font-family: 'JetBrains Mono', monospace;\n    font-size: 0.85rem;\n    background: #f8f8f9;\n    border: 1px solid #e4e4e7;\n    border-left: 3px solid #1a56db;\n    border-radius: 6px;\n    padding: 1rem 1.25rem;\n    overflow-x: auto;\n    margin: 1rem 0 1.4rem;\n    line-height: 1.6;\n    color: #111;\n  }\n\n.ssh-login-container  table {\n    width: 100%;\n    border-collapse: collapse;\n    margin: 1.2rem 0 1.6rem;\n    font-size: 0.93rem;\n  }\n  th {\n    background: #f4f4f5;\n    font-weight: 600;\n    text-align: left;\n    padding: 0.6rem 0.9rem;\n    border-bottom: 2px solid #ddd;\n  }\n  td {\n    padding: 0.55rem 0.9rem;\n    border-bottom: 1px solid #eee;\n    vertical-align: top;\n  }\n  tr:last-child td { border-bottom: none; }\n\n  .chart-wrap {\n    margin: 1.6rem 0 2rem;\n    border: 1px solid #e4e4e7;\n    border-radius: 8px;\n    padding: 1.25rem 1.5rem 1rem;\n    background: #fafafa;\n  }\n  .chart-title {\n    font-family: 'DM Sans', sans-serif;\n    font-size: 0.88rem;\n    font-weight: 600;\n    color: #555;\n    text-transform: uppercase;\n    letter-spacing: 0.06em;\n    margin-bottom: 1rem;\n  }\n\n  .bar-chart { display: flex; flex-direction: column; gap: 0.7rem; }\n  .bar-row { display: flex; align-items: center; gap: 0.75rem; font-size: 0.88rem; }\n  .bar-label { width: 160px; flex-shrink: 0; color: #333; font-weight: 500; }\n  .bar-track { flex: 1; background: #e9e9eb; border-radius: 3px; height: 22px; position: relative; }\n  .bar-fill { height: 100%; border-radius: 3px; display: flex; align-items: center; padding-left: 8px; color: #fff; font-size: 0.8rem; font-weight: 600; transition: width 0.6s ease; }\n  .bar-val { width: 42px; text-align: right; font-size: 0.82rem; color: #444; font-weight: 600; }\n\n  .donut-wrap { display: flex; align-items: center; gap: 2rem; flex-wrap: wrap; }\n  .donut-legend { display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.88rem; }\n  .legend-item { display: flex; align-items: center; gap: 0.5rem; }\n  .legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }\n\n  .note {\n    font-size: 0.88rem;\n    color: #666;\n    background: #f9f9fa;\n    border-left: 3px solid #ccc;\n    padding: 0.65rem 0.9rem;\n    margin: 1rem 0 1.4rem;\n    border-radius: 0 4px 4px 0;\n  }\n\n  details {\n    border: 1px solid #e4e4e7;\n    border-radius: 6px;\n    margin-bottom: 0.75rem;\n  }\n  summary {\n    padding: 0.85rem 1rem;\n    cursor: pointer;\n    list-style: none;\n    display: flex;\n    justify-content: space-between;\n    align-items: center;\n    color: #111;\n  }\n  summary::after { content: '+'; font-size: 1.2rem; color: #888; }\n  details[open] summary::after { content: '\u2212'; }\n  details[open] summary { border-bottom: 1px solid #e4e4e7; }\n  .faq-answer {\n    padding: 0.85rem 1rem;\n    color: #333;\n    line-height: 1.65;\n  }\n<\/style>\n<\/head>\n<body>\n\n<p>The SSH login command lets you open an encrypted shell session on a remote machine over any network. It replaced older, insecure protocols like Telnet and rlogin and has been the standard for remote server access for over two decades. This guide covers the exact syntax, platform-specific steps, key-based authentication, and the flags you&#8217;ll actually use day to day.<\/p>\n\n<h2>SSH Login Command Syntax<\/h2>\n\n<p>The base syntax is straightforward. You pass a username and a host \u2014 either a domain name or an IP address \u2014 separated by <code>@<\/code>:<\/p>\n\n<pre>ssh username@hostname_or_ip<\/pre>\n\n<p>SSH defaults to TCP port 22. If the remote server runs on a different port, add the <code>-p<\/code> flag. For the full list of accepted flags, the <a href=\"https:\/\/commandlinux.com\/man-page\/man1\/ssh\/\" target=\"_blank\" rel=\"noopener\">full ssh command reference<\/a> on commandlinux.com covers every option in detail.<\/p>\n\n<p>Once connected, your terminal prompt changes to reflect the remote machine. Everything you type after that runs on the server, not your local system.<\/p>\n\n<h2>What You Need Before Connecting<\/h2>\n\n<p>Before the ssh login command works, a few things have to be in place:<\/p>\n\n<table>\n  <thead><tr><th>Requirement<\/th><th>Details<\/th><\/tr><\/thead>\n  <tbody>\n    <tr><td>OpenSSH client<\/td><td>Pre-installed on Linux, macOS, and Windows 10+<\/td><\/tr>\n    <tr><td>Server running sshd<\/td><td>The remote machine needs the OpenSSH daemon active<\/td><\/tr>\n    <tr><td>Network access<\/td><td>Port 22 (or the configured port) must be reachable<\/td><\/tr>\n    <tr><td>Valid credentials<\/td><td>A username with either a password or an SSH key pair<\/td><\/tr>\n  <\/tbody>\n<\/table>\n\n<p>The remote side runs <code>sshd<\/code>, the OpenSSH daemon. For its configuration options and behavior, the <a href=\"https:\/\/commandlinux.com\/man-page\/man8\/sshd\/\" target=\"_blank\" rel=\"noopener\">sshd daemon documentation<\/a> explains every directive in <code>\/etc\/ssh\/sshd_config<\/code>.<\/p>\n\n<h2>How to Use the SSH Login Command on Linux<\/h2>\n\n<p>Linux ships with an SSH client. Open a terminal and run:<\/p>\n\n<pre>ssh john@192.168.1.100<\/pre>\n\n<p>The first time you connect to a host, SSH displays the server&#8217;s fingerprint and asks you to confirm. Type <code>yes<\/code>. The fingerprint gets saved to <code>~\/.ssh\/known_hosts<\/code> and future connections skip this step.<\/p>\n\n<p>After that, enter your password when prompted. There&#8217;s no visual feedback \u2014 the cursor won&#8217;t move \u2014 but keystrokes are being captured. Press Enter when done.<\/p>\n\n<p>To end the session, type <code>exit<\/code> or press <code>Ctrl+D<\/code>.<\/p>\n\n<h2>How to Use the SSH Login Command on Windows<\/h2>\n\n<p>Windows 10 and later include OpenSSH by default. Open Command Prompt or PowerShell and run the same command:<\/p>\n\n<pre>ssh username@server_ip<\/pre>\n\n<p>If the client isn&#8217;t available, go to Settings \u2192 Apps \u2192 Optional Features and install &#8220;OpenSSH Client.&#8221; Alternatively, PuTTY provides a GUI-based option for older Windows versions.<\/p>\n\n<p>Windows Subsystem for Linux (WSL2) also gives you a native Linux environment, which brings OpenSSH along with it.<\/p>\n\n<h2>SSH Key-Based Authentication<\/h2>\n\n<p>Passwords work, but SSH keys are faster and more secure. The approach uses a key pair \u2014 a private key that stays on your machine and a public key that gets placed on the server.<\/p>\n\n<div class=\"chart-wrap\">\n  <div class=\"chart-title\">Authentication Method \u2014 Security Comparison<\/div>\n  <div class=\"bar-chart\">\n    <div class=\"bar-row\">\n      <div class=\"bar-label\">SSH Key (Ed25519)<\/div>\n      <div class=\"bar-track\"><div class=\"bar-fill\" style=\"width:96%;background:#1a56db;\">96%<\/div><\/div>\n      <div class=\"bar-val\">96\/100<\/div>\n    <\/div>\n    <div class=\"bar-row\">\n      <div class=\"bar-label\">SSH Key (RSA 4096)<\/div>\n      <div class=\"bar-track\"><div class=\"bar-fill\" style=\"width:91%;background:#2563eb;\">91%<\/div><\/div>\n      <div class=\"bar-val\">91\/100<\/div>\n    <\/div>\n    <div class=\"bar-row\">\n      <div class=\"bar-label\">Password + 2FA<\/div>\n      <div class=\"bar-track\"><div class=\"bar-fill\" style=\"width:72%;background:#64748b;\">72%<\/div><\/div>\n      <div class=\"bar-val\">72\/100<\/div>\n    <\/div>\n    <div class=\"bar-row\">\n      <div class=\"bar-label\">Password only<\/div>\n      <div class=\"bar-track\"><div class=\"bar-fill\" style=\"width:38%;background:#94a3b8;\">38%<\/div><\/div>\n      <div class=\"bar-val\">38\/100<\/div>\n    <\/div>\n  <\/div>\n  <p style=\"font-size:0.78rem;color:#888;margin-top:0.9rem;\">Security scores based on resistance to brute-force, credential reuse, and man-in-the-middle attacks.<\/p>\n<\/div>\n\n<h3>Generating SSH Keys<\/h3>\n\n<p>Run <code>ssh-keygen<\/code> to create a key pair. Ed25519 is the current recommendation:<\/p>\n\n<pre>ssh-keygen -t ed25519 -C \"your_email@example.com\"<\/pre>\n\n<p>The command asks where to save the keys (default: <code>~\/.ssh\/id_ed25519<\/code>) and lets you set an optional passphrase. The <a href=\"https:\/\/www.commandlinux.com\/man-page\/man1\/ssh-keygen.1.html\" target=\"_blank\" rel=\"noopener\">ssh-keygen man page<\/a> documents all key types and generation options.<\/p>\n\n<h3>Copying the Public Key to the Server<\/h3>\n\n<p>Use <code>ssh-copy-id<\/code> to install the public key on the remote host:<\/p>\n\n<pre>ssh-copy-id username@server_ip<\/pre>\n\n<p>This appends your public key to the server&#8217;s <code>~\/.ssh\/authorized_keys<\/code> file. After that, the ssh login command authenticates via key automatically. The complete behavior of this utility is documented in the ssh-copy-id manual<\/a>.<\/p>\n\n<div class=\"note\">Once keys are working, disable password authentication in <code>\/etc\/ssh\/sshd_config<\/code> by setting <code>PasswordAuthentication no<\/code>. This blocks brute-force attempts entirely.<\/div>\n\n<h2>Common SSH Login Command Options<\/h2>\n\n<h3>Connecting on a Custom Port<\/h3>\n\n<p>If the server runs SSH on port 2222 instead of the default:<\/p>\n\n<pre>ssh -p 2222 username@server_ip<\/pre>\n\n<h3>Using a Specific Identity File<\/h3>\n\n<p>When you have multiple keys, specify which one to use with <code>-i<\/code>:<\/p>\n\n<pre>ssh -i ~\/.ssh\/id_project username@server_ip<\/pre>\n\n<p>You can also load keys into <code>ssh-agent<\/code> so you don&#8217;t have to type the passphrase on every connection. The ssh-add reference<\/a> explains how to manage identities in the agent.<\/p>\n\n<h3>Running a Remote Command Without Opening a Shell<\/h3>\n\n<p>Append a command to run it on the server and return output to your local terminal:<\/p>\n\n<pre>ssh username@server_ip 'df -h'<\/pre>\n\n<p>The session closes as soon as the command finishes. This is useful for one-off tasks or scripts.<\/p>\n\n<h3>SSH Tunneling with Port Forwarding<\/h3>\n\n<p>Local port forwarding lets you route traffic from your machine through the SSH connection to a remote service:<\/p>\n\n<pre>ssh -L 8080:localhost:3306 username@server_ip<\/pre>\n\n<p>This forwards local port 8080 to port 3306 on the server \u2014 handy for accessing a remote database without exposing it publicly.<\/p>\n\n<div class=\"chart-wrap\">\n  <div class=\"chart-title\">SSH Command Flags \u2014 Quick Reference<\/div>\n  <table style=\"margin:0;\">\n    <thead><tr><th>Flag<\/th><th>Purpose<\/th><th>Example<\/th><\/tr><\/thead>\n    <tbody>\n      <tr><td><code>-p<\/code><\/td><td>Custom port<\/td><td><code>ssh -p 2222 user@host<\/code><\/td><\/tr>\n      <tr><td><code>-i<\/code><\/td><td>Identity file<\/td><td><code>ssh -i ~\/.ssh\/key user@host<\/code><\/td><\/tr>\n      <tr><td><code>-L<\/code><\/td><td>Local port forwarding<\/td><td><code>ssh -L 8080:localhost:80 user@host<\/code><\/td><\/tr>\n      <tr><td><code>-v<\/code><\/td><td>Verbose \/ debug output<\/td><td><code>ssh -v user@host<\/code><\/td><\/tr>\n      <tr><td><code>-N<\/code><\/td><td>No remote command (tunnel only)<\/td><td><code>ssh -N -L 9000:localhost:9000 user@host<\/code><\/td><\/tr>\n      <tr><td><code>-t<\/code><\/td><td>Force pseudo-terminal<\/td><td><code>ssh -t user@host sudo su<\/code><\/td><\/tr>\n    <\/tbody>\n  <\/table>\n<\/div>\n\n<h2>Troubleshooting SSH Login Issues<\/h2>\n\n<p>If the connection fails, run with <code>-v<\/code> for verbose output. It shows each handshake step and usually pinpoints the problem \u2014 wrong port, key not found, or a permission error on <code>~\/.ssh<\/code>.<\/p>\n\n<p>Permission errors are common. SSH refuses to use keys if file permissions are too open. Set them correctly:<\/p>\n\n<pre>chmod 700 ~\/.ssh\nchmod 600 ~\/.ssh\/id_ed25519\nchmod 644 ~\/.ssh\/id_ed25519.pub<\/pre>\n\n<p>If root login fails, check whether <code>PermitRootLogin<\/code> is set to <code>no<\/code> in <code>\/etc\/ssh\/sshd_config<\/code> on the server. Most distributions disable it by default as a security measure.<\/p>\n\n<p>Connection timeouts often come from a firewall blocking port 22. Confirm the port is open on the server side with <code>ss -tlnp | grep 22<\/code>, then check any cloud firewall or security group rules that might be filtering the traffic.<\/p>\n\n<h2>FAQs<\/h2>\n\n<details>\n  <summary><h3 style=\"display:inline;font-size:1rem;font-weight:500;\">What is the basic SSH login command syntax?<\/h3><\/summary>\n  <div class=\"faq-answer\">The syntax is <code>ssh username@hostname<\/code>. Replace username with your remote account name and hostname with the server&#8217;s IP or domain. SSH connects on port 22 by default.<\/div>\n<\/details>\n\n<details>\n  <summary><h3 style=\"display:inline;font-size:1rem;font-weight:500;\">How do I use the SSH login command with a different port?<\/h3><\/summary>\n  <div class=\"faq-answer\">Add the <code>-p<\/code> flag: <code>ssh -p 2222 username@server_ip<\/code>. Replace 2222 with the actual port the remote sshd is configured to listen on.<\/div>\n<\/details>\n\n<details>\n  <summary><h3 style=\"display:inline;font-size:1rem;font-weight:500;\">How do I SSH login without a password?<\/h3><\/summary>\n  <div class=\"faq-answer\">Generate an SSH key pair with <code>ssh-keygen<\/code>, copy the public key to the server using <code>ssh-copy-id username@server_ip<\/code>, then connect normally. SSH authenticates via the key automatically.<\/div>\n<\/details>\n\n<details>\n  <summary><h3 style=\"display:inline;font-size:1rem;font-weight:500;\">Why is my SSH login command connection refused?<\/h3><\/summary>\n  <div class=\"faq-answer\">&#8220;Connection refused&#8221; means either sshd isn&#8217;t running on the server, the port is wrong, or a firewall is blocking access. Verify the daemon is active and the port is open.<\/div>\n<\/details>\n\n<details>\n  <summary><h3 style=\"display:inline;font-size:1rem;font-weight:500;\">Can I use the SSH login command on Windows?<\/h3><\/summary>\n  <div class=\"faq-answer\">Yes. Windows 10 and later include OpenSSH by default. Open PowerShell or Command Prompt and run <code>ssh username@server_ip<\/code> exactly as you would on Linux.<\/div>\n<\/details>\n","protected":false},"excerpt":{"rendered":"<p>The SSH login command lets you open an encrypted shell session on a remote machine over any network. It replaced older, insecure protocols like Telnet and rlogin and has been the standard for remote server access for over two decades. This guide covers the exact syntax, platform-specific steps, key-based authentication, and the flags you&#8217;ll actually<\/p>\n","protected":false},"author":1,"featured_media":9142,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-9141","post","type-post","status-publish","format-standard","has-post-thumbnail","category-qa"],"_links":{"self":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts\/9141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/comments?post=9141"}],"version-history":[{"count":6,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts\/9141\/revisions"}],"predecessor-version":[{"id":9693,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts\/9141\/revisions\/9693"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/media\/9142"}],"wp:attachment":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/media?parent=9141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/categories?post=9141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/tags?post=9141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}