🔑 Command: ssh (Secure Shell)
The ssh command is a protocol used to securely log into a remote computer over a network. It encrypts the entire connection, allowing you to run terminal commands on a server or another PC as if you were sitting right in front of it.
1. The "Why"
For a developer and researcher, ssh is the bridge between your local machine and the rest of the digital world.
- Manage Remote Servers: Connect to a VPS or a dedicated server to deploy your Supabase backend or host your web documentation viewer.
- Quantum Research: Log into high-performance computing (HPC) clusters at a university to run complex simulations that your Ryzen 5 3400G might struggle with.
- File Transfer: Move your LaTeX files or Java source code securely between your vivo smartphone and your Arch Linux PC.
- Security: Since you deal with Algerian payment hurdles and e-commerce,
sshensures your credentials aren't intercepted by "man-in-the-middle" attacks.
2. Basic Syntax
ssh username@remote_host
- username: Your account name on the remote machine.
- remote_host: The IP address (e.g.,
192.168.1.50) or domain name (e.g.,myserver.com).
3. Practical Examples
A. Connecting to a Local Machine
If you have another Linux laptop in your house:
ssh userName@192.168.1.15
B. Running a Single Command Remotely
You don't always need to "log in." You can just send a command and get the result back:
ssh user@host "ls /var/www/html"
C. Using a Non-Standard Port
For security, many servers don't use the default port (22). You specify the port with -p:
ssh -p 2222 userName@myserver.com
D. Copying Files Securely (scp)
While not technically the ssh command, scp uses the same protocol to move files:
scp preader_v1.java user@host:/home/user/backups/
4. SSH Keys: The Pro Way to Log In
Typing a password every time is slow and less secure. Most Linux users use SSH Keys (a pair of cryptographic files).
- Generate a key:
ssh-keygen -t ed25519 - Copy it to the server:
ssh-copy-id user@host - Result: Now you can log in instantly without a password.
5. Pro-Tips
- The Config File: If you have many servers, don't memorize IPs. Create a file at
~/.ssh/configand add entries like:
Then you can just typeHost myserver HostName 104.24.1.5 User userName Port 2222ssh myserver. - X11 Forwarding: Want to run a GUI app on a server but see the window on your local screen? Use
ssh -X. - Arch Linux Context: To use SSH, you must have the
opensshpackage installed. On Arch, you also need to start the service:sudo systemctl enable --now sshd.
6. Summary Reference
| Goal | Command |
|---|---|
| Standard Login | ssh user@host |
| Specific Port | ssh -p [port] user@host |
| Copy Key to Server | ssh-copy-id user@host |
| Copy File to Remote | scp file user@host:/path |
| Close Connection | Type exit or Ctrl + D |