{"id":125391,"date":"2025-12-02T16:12:17","date_gmt":"2025-12-02T16:12:17","guid":{"rendered":"\/ph\/tutorials\/basic-ssh-commands"},"modified":"2026-06-03T09:03:17","modified_gmt":"2026-06-03T09:03:17","slug":"basic-ssh-commands","status":"publish","type":"post","link":"\/ph\/tutorials\/basic-ssh-commands","title":{"rendered":"Basic SSH commands: SSH command examples, options, and cheat sheet"},"content":{"rendered":"<p>SSH commands let you securely connect to a remote server, run Linux commands, transfer files, manage SSH keys, and troubleshoot server access from the command line.&nbsp;<\/p><p>They send your instructions through the Secure Shell protocol, which encrypts every keystroke and file between your computer and the server, so you can log into a VPS, edit configs, restart services, and move backups without exposing your password.<\/p><p>Mastering SSH commands lets you connect to a server and run Linux commands once you know the syntax and options. From there, you can manage SSH keys, transfer files with SCP, SFTP, and rsync, save server details in a config, set up tunnels, and fix connection issues.<\/p><p>The most useful SSH commands you&rsquo;ll reach for daily:<\/p><ul class=\"wp-block-list\">\n<li><strong>ssh user@host<\/strong> &ndash; connects to a remote server.<\/li>\n\n\n\n<li><strong>ssh -p port user@host<\/strong> &ndash; connects through a custom SSH port.<\/li>\n\n\n\n<li><strong>ssh -i key_file user@host<\/strong> &ndash; connects with a private key.<\/li>\n\n\n\n<li><strong>ssh user@host command<\/strong> &ndash; runs a remote command without opening a full session.<\/li>\n\n\n\n<li><strong>ssh-keygen<\/strong> &ndash; generates SSH keys.<\/li>\n\n\n\n<li><strong>ssh-copy-id user@host<\/strong> &ndash; copies a public key to a server.<\/li>\n\n\n\n<li><strong>scp file user@host:\/path<\/strong> &ndash; copies files over SSH.<\/li>\n\n\n\n<li><strong>sftp user@host<\/strong> &ndash; opens a secure file transfer session.<\/li>\n\n\n\n<li><strong>ssh -L local:host:remote user@host<\/strong> &ndash; creates a local SSH tunnel.<\/li>\n\n\n\n<li><strong>ssh -v user@host<\/strong> &ndash; debugs an SSH connection.<\/li>\n<\/ul><p><\/p><h2 class=\"wp-block-heading\" id=\"h-what-are-ssh-commands\">What are SSH commands?<\/h2><p>SSH commands are instructions you run to use or configure the Secure Shell protocol, which encrypts the connection between your computer and a remote server. The term refers to two related concepts:<\/p><ul class=\"wp-block-list\">\n<li>Commands that directly use or <span style=\"margin: 0px;padding: 0px\">configure<a href=\"\/ph\/tutorials\/what-is-ssh\" target=\"_blank\" rel=\"noreferrer noopener\">&nbsp;SSH<\/a><\/span>, such as <strong>ssh<\/strong>, <strong>ssh-keygen<\/strong>, <strong>ssh-copy-id<\/strong>, <strong>scp<\/strong>, and <strong>sftp<\/strong>. You run these on your local machine to start a session, manage keys, or move files.<\/li>\n\n\n\n<li>Linux commands you run after connecting to the remote server, such as <strong>ls<\/strong>, <strong>cd<\/strong>, <strong>cat<\/strong>, and <strong>rm<\/strong>. These behave the same as they would on any Linux system, but they act on the server, not your local computer.<\/li>\n<\/ul><p>In both cases, the SSH protocol encrypts everything you send and receive. That&rsquo;s what makes it safe to manage servers over the public internet.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-connect-to-a-remote-server-with-ssh\">How to connect to a remote server with SSH<\/h2><p>You connect to a remote server with SSH by running the <strong>ssh<\/strong> command followed by your username, the server&rsquo;s host or IP address, and optionally a port number. The basic form is:<\/p><pre class=\"wp-block-code\"><code>ssh [options] user@host<\/code><\/pre><p>For example:<\/p><pre class=\"wp-block-code\"><code>ssh -p 2222 user@host<\/code><\/pre><p>Each part of the command has a clear meaning:<\/p><ul class=\"wp-block-list\">\n<li><strong>Username<\/strong> &ndash; the account you&rsquo;re logging into on the server, such as root or admin.<\/li>\n\n\n\n<li><strong>Host<\/strong> &ndash; the server&rsquo;s IP address or domain name, like <strong>203.0.113.10<\/strong> or <strong>srv-123.example.com<\/strong>.<\/li>\n\n\n\n<li><strong>Port <\/strong>&ndash; the SSH port on the server. The default is <strong>22<\/strong>, but many providers use a custom port for security.<\/li>\n<\/ul><p>If you&rsquo;re a Hostinger VPS customer, you can find your SSH details in hPanel. Go to VPS, click Manage, and open the Overview tab. You&rsquo;ll see the IP address, port, username, and password under VPS details, ready to copy.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a2160152fff6\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a2160152fff6\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/11\/image2-2-1024x685.png\" alt=\"Hostinger VPS hPanel Panel access\" class=\"wp-image-149942\" title=\"hpanel-vps-overview-panelaccess\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><figure class=\"wp-block-image size-large\"><a href=\"\/ph\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><p>On macOS, Linux, and Windows 10 or later, open the terminal and paste your <strong>ssh<\/strong> command. For older Windows or a graphical client, use <a href=\"\/ph\/tutorials\/how-to-use-putty-ssh\">PuTTY for SSH<\/a> and enter the host, port, and login details in its session window.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"6a21601532830\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6a21601532830\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/11\/image1.png\" alt=\"PuTTY Configuration on Windows\" class=\"wp-image-149941\" title=\"putty-config-windows\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>The first time you connect, SSH shows a fingerprint warning to confirm the server&rsquo;s identity. Type <strong>yes<\/strong> only if you trust the server. The fingerprint is then saved to your <strong>known_hosts<\/strong> file, and the warning won&rsquo;t return unless the server&rsquo;s key changes.<\/p><h2 class=\"wp-block-heading\" id=\"h-basic-ssh-command-syntax-and-options\">Basic SSH command syntax and options<\/h2><p>SSH commands follow a simple structure: the <strong>ssh<\/strong> command, any options you want, the user and host, and optionally a command to run on the remote server:<\/p><pre class=\"wp-block-code\"><code>ssh [options] user@host         <div class=\"console-box\">\n            <div class=\"console-box__head\">\n                <span class=\"console-box__bubble\"><\/span>\n                <span class=\"console-box__bubble console-box__bubble--yellow\"><\/span>\n                <span class=\"console-box__bubble console-box__bubble--green\"><\/span>\n            <\/div>\n            <p class=\"console-box__body\"><\/p>\n        <\/div>\n         <\/code><\/pre><p>Options change how SSH behaves. You can pick a custom port, map a specific key, turn on debug output, or forward ports. Here are the most useful ones you&rsquo;ll reach for as a beginner:<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>Option<\/td><td>What it does<\/td><td>Example<\/td><\/tr><tr><td><strong>-p<\/strong><\/td><td>Connects on a custom SSH port. Useful when <span style=\"margin: 0px;padding: 0px\">you&nbsp;<\/span><a href=\"\/ph\/tutorials\/how-to-change-ssh-port-vps\"><span style=\"margin: 0px;padding: 0px\">change<\/span> the SSH port<\/a> for security.<\/td><td><strong>ssh -p 2222 user@host<\/strong><\/td><\/tr><tr><td><strong>-i<\/strong><\/td><td>Uses a specific private key file.<\/td><td><strong>ssh -i ~\/.ssh\/id_ed25519 user@host<\/strong><\/td><\/tr><tr><td><strong>-v<\/strong><\/td><td>Turns on verbose mode for debugging. Add more <strong>v<\/strong>s for more detail (<strong>-vv<\/strong>, <strong>-vvv<\/strong>).<\/td><td><strong>ssh -v user@host<\/strong><\/td><\/tr><tr><td><strong>-C<\/strong><\/td><td>Compresses data during the session, which can help on slow connections.<\/td><td><strong>ssh -C user@host<\/strong><\/td><\/tr><tr><td><strong>-4 or -6<\/strong><\/td><td>Forces IPv4 or IPv6.<\/td><td><strong>ssh -4 user@host<\/strong><\/td><\/tr><tr><td><strong>-J<\/strong><\/td><td>Connects through a jump host.<\/td><td><strong>ssh -J jump@bastion user@target<\/strong><\/td><\/tr><tr><td><strong>-L<\/strong><\/td><td>Sets up local port forwarding.<\/td><td><strong>ssh -L 8080:localhost:80 user@host<\/strong><\/td><\/tr><\/tbody><\/table><\/figure><p>You can combine options as needed. For example, <strong>ssh -p 2222 -i ~\/.ssh\/id_ed25519 user@host<\/strong> connects to a custom port using a specific key.<\/p><h2 class=\"wp-block-heading\" id=\"h-basic-linux-commands-to-use-after-connecting-with-ssh\">Basic Linux commands to use after connecting with SSH<\/h2><p>Once you&rsquo;re logged in, you&rsquo;ll use standard <a href=\"\/ph\/tutorials\/linux-commands\">Linux commands<\/a> to move around the server, manage files, and check the system. These commands run on the remote server, not your local machine. Here are the most common ones grouped by what they do.<\/p><h3 class=\"wp-block-heading\">Navigation<\/h3><p>Knowing where you are and how to move between folders is the first thing you&rsquo;ll do after logging in.<\/p><ul class=\"wp-block-list\">\n<li><strong>pwd <\/strong>prints the full path of your current directory. It answers the question &ldquo;where am I right now?&rdquo; and is the safest command to run first on an unfamiliar server.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>pwd<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>ls<\/strong> lists files and folders in the current directory. Add <strong>-la<\/strong> to see hidden files, permissions, owners, and sizes, which is useful when checking config files or log directories.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>ls -la \/var\/log<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>cd<\/strong> changes the current directory. Use <strong>cd ..<\/strong> to go up one level, <strong>cd ~<\/strong> to jump to your home folder, and <strong>cd &ndash;<\/strong> to return to the previous directory.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>cd \/var\/www\/html<\/code><\/pre><h3 class=\"wp-block-heading\">File and directory creation<\/h3><p>You&rsquo;ll often need to create folders for projects, backups, or config files.<\/p><ul class=\"wp-block-list\">\n<li><strong>mkdir<\/strong> creates a new directory. Add <strong>-p<\/strong> to create nested folders in one go without errors if a parent already exists.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>mkdir -p \/home\/user\/backups\/2025<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>touch<\/strong> creates an empty file or updates the timestamp on an existing one. It&rsquo;s handy for placeholder files or for testing write permissions.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>touch \/var\/www\/html\/test.txt<\/code><\/pre><h3 class=\"wp-block-heading\">File viewing and editing<\/h3><p>When you&rsquo;re troubleshooting a server, most of the work is reading log files and editing configs.<\/p><ul class=\"wp-block-list\">\n<li><strong>cat<\/strong> prints the full contents of a file to the screen. It&rsquo;s best for short files. For large logs, use less instead, so you can scroll.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>cat \/etc\/hostname<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>less<\/strong> opens a file for scrolling. Use the arrow keys or <strong>Page Up<\/strong> and <strong>Page Down<\/strong> to move, <strong>\/word<\/strong> to search, and <strong>q<\/strong> to quit.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>less \/var\/log\/nginx\/error.log<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>tail<\/strong> shows the last lines of a file. Add <strong>-f<\/strong> to follow new lines as they&rsquo;re written, which is the standard way to watch logs in real time.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>tail -f \/var\/log\/nginx\/access.log<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>head<\/strong> shows the first lines of a file. Useful for checking the top of large CSVs or log files without loading the whole thing.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>head -n 20 \/var\/log\/syslog<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>nano<\/strong> opens a simple text editor right in the terminal. Press <strong>Ctrl+O<\/strong> to save, <strong>Ctrl+X <\/strong>to exit. It&rsquo;s the easiest editor for beginners.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>nano \/etc\/nginx\/nginx.conf<\/code><\/pre><h3 class=\"wp-block-heading\">File management<\/h3><p>These commands copy, move, rename, and delete files. Some of them can overwrite data without asking, so read the safety notes carefully.<\/p><ul class=\"wp-block-list\">\n<li><strong>cp<\/strong> copies a file or folder. Add <strong>-r<\/strong> to copy a directory and all its contents. Add <strong>-i<\/strong> to be asked before overwriting.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>cp -r \/var\/www\/html \/var\/www\/html_backup<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>mv<\/strong> moves or renames a file. There&rsquo;s no separate rename command in Linux. Watch out: if the destination file already exists, <strong>mv<\/strong> overwrites it silently.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>mv config.old.conf config.bak<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>rm<\/strong> deletes files. Add <strong>-r<\/strong> to delete a folder and its contents. <strong>rm<\/strong> does not move files to a trash bin. Deleted files are gone immediately.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>rm \/tmp\/old-log.txt<\/code><\/pre><p>    <p class=\"warning\">\n        <strong>Warning!<\/strong> Never run&nbsp;rm-rf \/ or rm -rf \/*. These commands delete every file on the server. Always double-check the path before running rm -r, especially when using wildcards like *.    <\/p>\n    \n\n\n\n<\/p><h3 class=\"wp-block-heading\">Search<\/h3><p>Finding the right file or the right line in a large file saves hours of scrolling.<\/p><ul class=\"wp-block-list\">\n<li><strong>find<\/strong> searches for files by name, type, size, or date. It&rsquo;s the most flexible search tool in Linux.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>find \/var\/www -name \"*.php\" -mtime -7<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>grep<\/strong> searches inside files for a word or pattern. Add <strong>-r<\/strong> to search recursively and <strong>-i<\/strong> to ignore case.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>grep -ri \"error\" \/var\/log\/nginx<\/code><\/pre><h3 class=\"wp-block-heading\">Archives and downloads<\/h3><p>You&rsquo;ll often need to compress files for backups or grab installers from the internet.<\/p><ul class=\"wp-block-list\">\n<li><strong>tar<\/strong> creates and extracts archive files. The most common usage is <strong>tar -czvf<\/strong> to create a compressed <strong>.tar.gz<\/strong> archive and <strong>tar -xzvf<\/strong> to extract one.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>tar -czvf backup.tar.gz \/var\/www\/html<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>wget<\/strong> downloads files from a URL straight to the server.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>wget https:\/\/example.com\/installer.sh<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>curl<\/strong> also downloads files and is the standard tool for testing APIs and HTTP responses.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>curl -O https:\/\/example.com\/file.zip<\/code><\/pre><h3 class=\"wp-block-heading\">System checks<\/h3><p>When something goes wrong, you&rsquo;ll need to check disk space, running processes, and active services.<\/p><ul class=\"wp-block-list\">\n<li><strong>df<\/strong> shows free and used disk space on each mounted filesystem. Add <strong>-h<\/strong> for human-readable sizes (GB, MB).<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>df -h<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>du<\/strong> shows the size of files and folders. <strong>du -sh *<\/strong> is the quickest way to see which folders are eating up your space.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>du -sh \/var\/log\/*<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>top<\/strong> shows running processes in real time, sorted by CPU usage. Press q to exit. For a nicer interface, install and use htop.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>top<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>systemctl<\/strong> controls services on systems that use systemd, which covers most modern Linux distributions. Use it to start, stop, restart, and check the status of services such as NGINX or MySQL.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>systemctl status nginx<\/code><\/pre><h2 class=\"wp-block-heading\" id=\"h-ssh-key-commands\">SSH key commands<\/h2><p>SSH keys are a pair of files that let you log in without a password. The private key stays on your computer; the public key goes on the server. When you connect, the server uses the public key to verify that your machine holds the matching private key.&nbsp; This is safer than passwords because keys can&rsquo;t be guessed or brute-forced.<\/p><p>You can <a href=\"\/ph\/tutorials\/how-to-set-up-ssh-keys\">set up SSH keys<\/a> in three short steps.<\/p><h3 class=\"wp-block-heading\">Generate an SSH key pair<\/h3><p>Use ssh-keygen to create a new key pair. The <strong>Ed25519<\/strong> algorithm is the modern default, faster and more secure than older RSA keys:<\/p><pre class=\"wp-block-code\"><code>ssh-keygen -t ed25519 -C \"your_email@example.com\"<\/code><\/pre><p>The command asks where to save the key (press <strong>Enter<\/strong> to use the default <strong>~\/.ssh\/id_ed25519<\/strong>) and lets you add a passphrase for extra protection.<\/p><h3 class=\"wp-block-heading\">Copy your public key to the server<\/h3><p><strong>ssh-copy-id<\/strong> is the easiest way to install your public key on a remote server.<\/p><pre class=\"wp-block-code\"><code>ssh-copy-id user@host<\/code><\/pre><p>After this runs, you can <a href=\"\/ph\/tutorials\/how-to-setup-passwordless-ssh\">set up passwordless SSH<\/a> and log in without typing your password.<\/p><h3 class=\"wp-block-heading\">Connect with a specific private key<\/h3><p>If you have more than one key, use <strong>-i<\/strong> to pick the one you want.<\/p><pre class=\"wp-block-code\"><code>ssh -i ~\/.ssh\/id_ed25519 user@host<\/code><\/pre><h3 class=\"wp-block-heading\">Manage keys with ssh-agent<\/h3><p><strong>ssh-agent<\/strong> keeps your decrypted keys in memory so you don&rsquo;t have to type your passphrase every time you connect.<\/p><pre class=\"wp-block-code\"><code>eval \"$(ssh-agent -s)\"\n\nssh-add ~\/.ssh\/id_ed25519<\/code><\/pre><p>Once keys are working reliably, you can <a href=\"\/ph\/tutorials\/how-to-disable-ssh-password-login-on-vps\">disable SSH password login<\/a> to block password-based attacks entirely.<\/p><p>    <p class=\"warning\">\n        <strong>Warning!<\/strong> Your private key file is the equivalent of a password. Never share it, email it, paste it into chat, or upload it to a public repository. If you think a private key has been exposed, remove the matching public key from every server it was installed on and generate a new pair.    <\/p>\n    \n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-run-remote-commands-over-ssh\">How to run remote commands over SSH<\/h2><p>You can run a single command on a remote server without opening a full interactive session by adding the command to the end of <span style=\"margin: 0px;padding: 0px\">your<strong>&nbsp;ssh<\/strong><\/span> line. The server runs it, prints the output, and closes the connection.<\/p><pre class=\"wp-block-code\"><code>ssh user@host \"df -h\"<\/code><\/pre><p>This is useful for quick checks and for scripting. Common examples include:<\/p><ul class=\"wp-block-list\">\n<li>Checking disk space: <strong>ssh user@host &ldquo;df -h&rdquo;<\/strong>.<\/li>\n\n\n\n<li>Listing files in a folder: <strong>ssh user@host &ldquo;ls -la \/var\/www&rdquo;<\/strong>.<\/li>\n\n\n\n<li>Checking a service status: <strong>ssh user@host &ldquo;systemctl status nginx&rdquo;<\/strong>.<\/li>\n\n\n\n<li>Restarting a service: <strong>ssh user@host &ldquo;sudo systemctl restart nginx<\/strong>&ldquo;.<\/li>\n<\/ul><p>Wrap longer commands in quotes so your local shell sends them as one string. For example, <strong>ssh user@server &ldquo;ls -la \/var\/log&rdquo;<\/strong> runs the full <strong>ls<\/strong> command on the remote server rather than breaking it apart locally.<\/p><p>For commands with their own quotes, wrap the outside in single quotes and keep double quotes inside, or escape them with a backslash. Both <strong>ssh user@server &lsquo;grep &ldquo;error&rdquo; \/var\/log\/syslog&rsquo;<\/strong> and <strong>ssh user@server &ldquo;grep &ldquo;error&rdquo; \/var\/log\/syslog&rdquo;<\/strong> work the same way.<\/p><h2 class=\"wp-block-heading\" id=\"h-ssh-file-transfer-commands\">SSH file transfer commands<\/h2><p>SSH isn&rsquo;t just for running commands. It also handles secure file transfers between your computer and the server. There are three main tools, each one suited for a different job.<\/p><h3 class=\"wp-block-heading\">Copy files with SCP<\/h3><p>SCP (secure copy) is the simplest way to move a single file or folder over SSH. The <a href=\"\/ph\/tutorials\/linux-scp-command\">SCP command<\/a> follows the same pattern as <strong>cp<\/strong>, except one side is on a remote server.<\/p><p>Copy a local file to the server:<\/p><pre class=\"wp-block-code\"><code>scp report.pdf user@host:\/home\/user\/<\/code><\/pre><p>Copy a file from the server to your local machine:<\/p><pre class=\"wp-block-code\"><code>scp user@host:\/var\/log\/nginx\/access.log .\/<\/code><\/pre><p>Copy a whole folder with <strong>-r<\/strong>:<\/p><pre class=\"wp-block-code\"><code>scp -r .\/website user@host:\/var\/www\/<\/code><\/pre><p>Modern OpenSSH versions use SFTP under the hood when you run <strong>scp<\/strong>, since the original SCP protocol was deprecated in OpenSSH 9.0. The command and syntax still work the same way.<\/p><h3 class=\"wp-block-heading\">Transfer files with SFTP<\/h3><p>SFTP (SSH File Transfer Protocol) opens an interactive session in which you can list, upload, download, and rename files using commands such as ls, get, put, and cd. It&rsquo;s a good choice when you want to browse the remote filesystem before deciding what to move.&nbsp;<\/p><p>You can <a href=\"\/ph\/tutorials\/how-to-use-sftp-to-safely-transfer-files\">use SFTP to transfer files securely<\/a> via both the command line and graphical clients such as FileZilla.<\/p><pre class=\"wp-block-code\"><code>sftp user@host<\/code><\/pre><p>Once connected, try:<\/p><pre class=\"wp-block-code\"><code>ls\n\ncd \/var\/www\n\nget index.html\n\nput new-page.html\n\nexit<\/code><\/pre><h3 class=\"wp-block-heading\">Sync folders with <strong>rsync<\/strong><\/h3><p>For large transfers, recurring backups, or keeping two folders in sync, the <a href=\"\/ph\/tutorials\/how-to-use-rsync\">rsync command<\/a> is the right tool. It only copies files that have changed, saving time and bandwidth.<\/p><pre class=\"wp-block-code\"><code>rsync -avz .\/local-folder\/ user@host:\/var\/www\/site\/<\/code><\/pre><p><span style=\"margin: 0px;padding: 0px\">The<strong>&nbsp;-a<\/strong><\/span> flag preserves permissions and timestamps, <strong>-v<\/strong> shows what&rsquo;s being transferred, and <strong>-z<\/strong> compresses data on the fly.<\/p><p>Also, the trailing slash on the source folder matters. With it, <strong>rsync<\/strong> copies the folder&rsquo;s contents. Without it, <strong>rsync<\/strong> copies the folder itself into the destination.<\/p><h2 class=\"wp-block-heading\" id=\"h-ssh-config-file-shortcuts\">SSH config file shortcuts<\/h2><p>The SSH config file lets you save server details such as host, username, port, and key path so you can connect using a short alias instead of typing the full command every time.<\/p><p>The file lives at <strong>~\/.ssh\/config<\/strong> on your local machine. If it doesn&rsquo;t exist, create it. Here&rsquo;s an example:<\/p><pre class=\"wp-block-code\"><code>Host myvps&nbsp;\n\nHostName 203.0.113.10&nbsp;\n\nUser admin&nbsp;\n\nPort 2222&nbsp;\n\nIdentityFile ~\/.ssh\/id_ed25519<\/code><\/pre><p>With that saved, you can connect by typing:<\/p><pre class=\"wp-block-code\"><code>ssh myvps<\/code><\/pre><p>You can add as many <strong>Host<\/strong> blocks as you want, one per server. This is also handy when you use jump hosts or different keys per server.<\/p><h2 class=\"wp-block-heading\" id=\"h-ssh-tunneling-and-port-forwarding-commands\">SSH tunneling and port forwarding commands<\/h2><p>SSH tunneling forwards network traffic through an encrypted SSH connection. It&rsquo;s useful for reaching services that aren&rsquo;t exposed to the public internet, such as a database that only listens on the server&rsquo;s local interface.<\/p><p>There are three main types of tunnels:<\/p><ul class=\"wp-block-list\">\n<li><strong>Local port forwarding<\/strong> sends traffic from a port on your computer to a port on the remote server. Use it to access a remote service as if it were running locally.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>ssh -L 3306:localhost:3306 user@host<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>Remote port forwarding<\/strong> does the opposite: it sends traffic from a port on the remote server to a port on your local machine.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>ssh -R 8080:localhost:80 user@host<\/code><\/pre><ul class=\"wp-block-list\">\n<li><strong>Dynamic port forwarding <\/strong>turns SSH into a SOCKS proxy, which you can configure in your browser to route all traffic through the server.<\/li>\n<\/ul><pre class=\"wp-block-code\"><code>ssh -D 1080 user@host<\/code><\/pre><p>    <p class=\"warning\">\n        <strong>Warning!<\/strong> Before opening a tunnel, know what service you're exposing and to whom. Forwarding a database or admin panel for your own use is fine, but leaving a tunnel open or pointing at the wrong port can expose sensitive services to the wrong network.    <\/p>\n    \n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-troubleshoot-ssh-connection-errors\">How to troubleshoot SSH connection errors<\/h2><p>Most SSH errors fall into a handful of categories, and the verbose flag <strong>-v<\/strong> is your best tool for spotting the cause. Run <strong>ssh -v user@host<\/strong> to see exactly where the connection breaks.<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td><strong>Error<\/strong><\/td><td><strong>Likely cause<\/strong><\/td><td><strong>What to try<\/strong><\/td><\/tr><tr><td><a href=\"\/ph\/tutorials\/ssh-connection-refused\">SSH connection refused<\/a><\/td><td>SSH service isn&rsquo;t running, or the firewall is blocking the port.<\/td><td>Check the server&rsquo;s status and confirm the port is open.<\/td><\/tr><tr><td>Connection timed out<\/td><td>Wrong IP or host, or the server is unreachable.<\/td><td>Ping the host and confirm you&rsquo;re using the correct address.<\/td><\/tr><tr><td>Permission denied (publickey)<\/td><td>Your key isn&rsquo;t authorized on the server, or the key file has the wrong permissions.<\/td><td>Run chmod <strong>600 ~\/.ssh\/id_ed25519<\/strong> locally. On the server, confirm your public key is in <strong>~\/.ssh\/authorized_keys<\/strong> and check that <strong>~\/.ssh<\/strong> is set to <strong>700<\/strong> and <strong>authorized_keys<\/strong> to <strong>600<\/strong>.<\/td><\/tr><tr><td>Permission denied (password)<\/td><td>Wrong username or password, or password login is disabled.<\/td><td>Double-check credentials and confirm <strong>PasswordAuthentication<\/strong> settings in <strong>\/etc\/ssh\/sshd_config.<\/strong><\/td><\/tr><tr><td>Port 22: Connection refused<\/td><td>You&rsquo;re using the default port, but the server uses a custom one.<\/td><td>Add <strong>-p<\/strong> with the correct port.<\/td><\/tr><tr><td>Host key verification failed<\/td><td>The server&rsquo;s key has changed since your last visit.<\/td><td>If you trust the change (like a server rebuild), remove the old entry with <strong>ssh-keygen -R host<\/strong>. If you didn&rsquo;t expect a change, stop and investigate before connecting.<\/td><\/tr><\/tbody><\/table><\/figure><p>    <p class=\"warning\">\n        <strong>Warning!<\/strong> A sudden host key change can mean the server was rebuilt, but it can also mean someone is intercepting your connection. Don't blindly accept new host keys for servers you've connected to before. Verify with your hosting provider first.    <\/p>\n    \n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-next-steps-for-using-ssh-on-your-server\">Next steps for using SSH on your server<\/h2><p>You now have the SSH commands and Linux basics to manage a remote server. The next step is to log in and practice. Move between directories with <strong>cd<\/strong>, list files with <strong>ls<\/strong>, and watch logs with tail <strong>-f<\/strong> until it feels natural.<\/p><p>Then focus on three habits: switch to SSH keys instead of passwords, keep local backups of important config files with SCP or rsync before making changes on the server, and run <strong>ssh -v<\/strong> first whenever a connection fails.<\/p><p>A few things worth exploring next:<\/p><ul class=\"wp-block-list\">\n<li>Run long tasks without losing them if your SSH session drops by <span style=\"margin: 0px;padding: 0px\">using&nbsp;<\/span><a href=\"\/ph\/tutorials\/how-to-install-and-use-linux-screen\"><span style=\"margin: 0px;padding: 0px\">Linux<\/span> Screen<\/a> or <strong>tmux<\/strong>.<\/li>\n\n\n\n<li>Save common server details in your <strong>~\/.ssh\/config<\/strong> so you can connect with short aliases.<\/li>\n\n\n\n<li>Automate routine checks with short remote commands, like a daily disk space report.<\/li>\n<\/ul><p>The more you use SSH, the more it becomes a quiet background tool: you stop thinking about the protocol and just focus on running your server.<\/p><p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSH commands let you securely connect to a remote server, run Linux commands, transfer files, manage SSH keys, and troubleshoot server access from the command line.&nbsp; They send your instructions through the Secure Shell protocol, which encrypts every keystroke and file between your computer and the server, so you can log into a VPS, edit [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ph\/tutorials\/basic-ssh-commands\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":633,"featured_media":130531,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Basic SSH commands: SSH command examples, options, and cheat sheet","rank_math_description":"Learn how to navigate and work with files in a Linux environment. We'll provide a list of basic SSH commands and examples on how to use them.","rank_math_focus_keyword":"ssh commands","footnotes":""},"categories":[22639],"tags":[],"class_list":["post-125391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/basic-ssh-commands\/","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/commandes-ssh-de-base-que-vous-devez-connaitre","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/comandos-ssh-esenciales","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-menggunakan-command-ssh","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/basic-ssh-commands\/","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/comandos-ssh-esenciales","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/comandos-ssh-esenciales","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/comandos-ssh-esenciales","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/basic-ssh-commands\/","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/basic-ssh-commands\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/basic-ssh-commands\/","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/basic-ssh-commands\/","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/basic-ssh-commands\/","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/basic-ssh-commands\/","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/125391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/users\/633"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/comments?post=125391"}],"version-history":[{"count":4,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/125391\/revisions"}],"predecessor-version":[{"id":130530,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/125391\/revisions\/130530"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/media\/130531"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/media?parent=125391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/categories?post=125391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/tags?post=125391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}