{"id":1637,"date":"2024-02-25T00:00:00","date_gmt":"2024-02-25T05:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=1637"},"modified":"2024-02-02T14:35:16","modified_gmt":"2024-02-02T19:35:16","slug":"ssh-cheat-sheet","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/ssh-cheat-sheet\/","title":{"rendered":"SSH Cheat Sheet"},"content":{"rendered":"\n<p>Secure Shell (SSH) is a widely-used protocol for securely connecting to remote servers. This cheat sheet provides essential SSH commands for managing remote connections, file transfers, and more.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Introduction:<\/strong><\/h4>\n\n\n\n<p>SSH provides encrypted communication over a network, allowing users to connect to and manage remote servers securely. Key-based authentication and secure file transfer make SSH a fundamental tool for system administrators and developers.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Connecting to a Remote Server:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>ssh [username]@[hostname]<\/code><\/td><td>Connect to a remote server with SSH.<\/td><\/tr><tr><td><code>ssh -p [port] [username]@[hostname]<\/code><\/td><td>Specify a custom SSH port for connection.<\/td><\/tr><tr><td><code>ssh -i [private_key] [username]@[hostname]<\/code><\/td><td>Connect using a specific private key file.<\/td><\/tr><tr><td><code>ssh -X [username]@[hostname]<\/code><\/td><td>Enable X11 forwarding for GUI applications.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>File Transfer with SCP:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>scp [file] [username]@[hostname]:[destination]<\/code><\/td><td>Copy a file to a remote server.<\/td><\/tr><tr><td><code>scp -r [directory] [username]@[hostname]:[destination]<\/code><\/td><td>Copy a directory and its contents recursively.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>SSH Key Management:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>ssh-keygen<\/code><\/td><td>Generate a new SSH key pair.<\/td><\/tr><tr><td><code>ssh-copy-id [username]@[hostname]<\/code><\/td><td>Copy the public key to the remote server.<\/td><\/tr><tr><td><code>ssh-add [private_key]<\/code><\/td><td>Add a private key to the SSH agent.<\/td><\/tr><tr><td><code>ssh-keyscan [hostname] &gt;&gt; ~\/.ssh\/known_hosts<\/code><\/td><td>Add a host key to the known_hosts file.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Tunneling and Port Forwarding:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>ssh -L [local_port]:[destination_host]:[destination_port] [username]@[hostname]<\/code><\/td><td>Local port forwarding.<\/td><\/tr><tr><td><code>ssh -R [remote_port]:[destination_host]:[destination_port] [username]@[hostname]<\/code><\/td><td>Remote port forwarding.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Executing Commands Remotely:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>ssh [username]@[hostname] [command]<\/code><\/td><td>Execute a command on the remote server.<\/td><\/tr><tr><td><code>ssh -t [username]@[hostname] [command]<\/code><\/td><td>Force pseudo-terminal allocation.<\/td><\/tr><tr><td><code>ssh -T [username]@[hostname] [command]<\/code><\/td><td>Disable pseudo-terminal allocation.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Miscellaneous:<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>ssh -v [username]@[hostname]<\/code><\/td><td>Verbose mode, display detailed debugging output.<\/td><\/tr><tr><td><code>ssh -o [option=value] [username]@[hostname]<\/code><\/td><td>Set SSH options using the -o flag.<\/td><\/tr><tr><td><code>ssh -J [jump_host] [username]@[hostname]<\/code><\/td><td>Use a jump host to reach the target host.<\/td><\/tr><tr><td><code>ssh -D [local_port] [username]@[hostname]<\/code><\/td><td>Dynamic port forwarding (SOCKS proxy).<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>SSH is a critical tool for secure remote server management. This cheat sheet offers a quick reference for commonly used SSH commands, covering connection, file transfer, key management, and advanced features like port forwarding. Whether you are a system administrator or a developer, mastering these commands will enhance your efficiency in working with remote servers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Secure Shell (SSH) is a widely-used protocol for securely connecting to remote servers. This cheat sheet provides essential SSH commands for managing remote connections, file transfers, and more. Introduction: SSH provides encrypted communication over a network, allowing users to connect to and manage remote servers securely. Key-based authentication and secure file transfer make SSH a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,265],"tags":[35,36],"class_list":["post-1637","post","type-post","status-publish","format-standard","hentry","category-linux","category-reference","tag-linux","tag-ssh"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=1637"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1637\/revisions"}],"predecessor-version":[{"id":1638,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1637\/revisions\/1638"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=1637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=1637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=1637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}