WebsiteTemplate/cheatsheets/ssh.html
2026-01-25 11:33:37 -04:00

177 lines
6.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self' data:; img-src 'self' data:; connect-src 'self'; base-uri 'self'; form-action 'self' https://defcon.social https://bsky.app;">
<meta http-equiv="X-Content-Type-Options" content="nosniff">
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="icon" type="image/x-icon" href="../favicon.ico">
<script>
// Apply theme immediately to prevent flash
(function() {
const theme = localStorage.getItem('theme') ||
(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.setAttribute('data-theme', theme);
})();
</script>
<title>ssh Cheatsheet - Launch Pad</title>
</head>
<body>
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode">
<svg class="theme-icon theme-icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
<svg class="theme-icon theme-icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>
</button>
<br/><br/>
<div class="name">
__ _______________________ _________._________________________
/ \ / \_ _____/\______ \/ _____/| \__ ___/\_ _____/
\ \/\/ /| __)_ | | _/\_____ \ | | | | | __)_
\ / | \ | | \/ \| | | | | \
\__/\ / /_______ / |______ /_______ /|___| |____| /_______ /
\/ \/ \/ \/ \/
</div>
<div class="blog-page-header">
<div class="blog-header-content">
<a href="/cheatsheets" class="back-link" title="Back to Cheatsheets">
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="42" viewBox="0 0 24 24" class="home-icon"><path fill="currentColor" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
</a>
<h1 class="blog-page-title">ssh Cheatsheet</h1>
</div>
</div>
<div class="blog-post-container">
<div class="blog-posts-container" style="max-width: 900px; margin: 0 auto;">
<div class="blog-post">
<div class="blog-post-content">
<p><a href="index.html">← Back to cheatsheets</a></p>
<p><a href="../index.html">← Home</a></p>
<hr>
<p>SSH (Secure Shell) is a protocol for secure remote login and command execution. Essential for managing remote servers, secure file transfer, and tunneling.</p>
<hr>
<h2>Basic Connection</h2>
<ul>
<li>ssh user@hostname - Connect to remote host</li>
</ul>
<ul>
<li>ssh user@hostname -p 2222 - Connect on custom port</li>
</ul>
<ul>
<li>ssh -i ~/.ssh/key.pem user@hostname - Use specific key file</li>
</ul>
<ul>
<li>ssh -v user@hostname - Verbose output (debugging)</li>
</ul>
<hr>
<h2>Port Forwarding</h2>
<ul>
<li>ssh -L 8080:localhost:80 user@hostname - Local port forward</li>
</ul>
<ul>
<li>ssh -R 8080:localhost:80 user@hostname - Remote port forward</li>
</ul>
<ul>
<li>ssh -D 1080 user@hostname - Dynamic SOCKS proxy</li>
</ul>
<ul>
<li>ssh -L 8080:remote:80 -N user@hostname - Forward without shell</li>
</ul>
<hr>
<h2>File Transfer</h2>
<ul>
<li>scp file.txt user@hostname:/path/ - Copy file to remote</li>
</ul>
<ul>
<li>scp user@hostname:/path/file.txt . - Copy file from remote</li>
</ul>
<ul>
<li>scp -r dir/ user@hostname:/path/ - Copy directory recursively</li>
</ul>
<ul>
<li>rsync -avz dir/ user@hostname:/path/ - Sync with rsync</li>
</ul>
<hr>
<h2>Remote Execution</h2>
<ul>
<li>ssh user@hostname "command" - Execute command remotely</li>
</ul>
<ul>
<li>ssh user@hostname "cat file.txt" - Read remote file</li>
</ul>
<ul>
<li>cat file.txt | ssh user@hostname "cat > remote.txt" - Pipe to remote</li>
</ul>
<hr>
<h2>Configuration</h2>
<ul>
<li>~/.ssh/config - SSH client configuration file</li>
</ul>
<ul>
<li>Host alias - Define host alias</li>
</ul>
<ul>
<li>HostName real.hostname.com - Set hostname</li>
</ul>
<ul>
<li>User username - Set default user</li>
</ul>
<ul>
<li>IdentityFile ~/.ssh/key - Specify key file</li>
</ul>
<ul>
<li>Port 2222 - Set port</li>
</ul>
<hr>
<h2>Common Examples</h2>
<h3>Basic Connection</h3>
<pre><code>ssh user@example.com</code></pre>
<p>Connect to remote server.</p>
<h3>Port Forwarding</h3>
<pre><code>ssh -L 8080:localhost:80 user@example.com</code></pre>
<p>Forward local port 8080 to remote port 80.</p>
<h3>Copy File</h3>
<pre><code>scp file.txt user@example.com:/home/user/</code></pre>
<p>Copy file to remote server.</p>
<h3>Execute Command</h3>
<pre><code>ssh user@example.com "ls -la"</code></pre>
<p>Run command on remote server.</p>
<h3>SSH Config</h3>
<pre><code>Host myserver
HostName example.com
User myuser
IdentityFile ~/.ssh/id_ed25519
Port 2222</code></pre>
<p>Configure SSH alias in ~/.ssh/config.</p>
<hr>
<h2>Tips</h2>
<ul>
<li>Use key-based authentication instead of passwords</li>
</ul>
<ul>
<li>Configure ~/.ssh/config for easier connections</li>
</ul>
<ul>
<li>Use -N flag for port forwarding without shell</li>
</ul>
<ul>
<li>rsync is often faster than scp for large transfers</li>
</ul>
<ul>
<li>Use ControlMaster for connection multiplexing</li>
</ul>
<ul>
<li>Keep SSH keys secure and use passphrases</li>
</ul>
<ul>
<li>Disable password authentication on servers when possible</li>
</ul>
</div>
</div>
</div>
</div>
<script async type="text/javascript" src="../blog/analytics.js"></script>
<script src="../theme.js"></script>
</body>
</html>