💻 Remote Login and Command Execution
With SSH, you don't always need a full interactive session. You can run commands or even entire scripts on a remote machine directly from your local terminal. This is a powerful feature for automation and remote system management.
Running Commands Remotely with SSH
You can run a single command on a remote machine like this:
This logs into 192.168.1.10 as alice, runs ls -l /home/alice, then exits. The output appears right in your local terminal.
Running Scripts Remotely
You can also execute entire scripts on a remote server:
The < local_script.sh sends your local script over SSH and executes it remotely. This is useful for automating updates, backups, or deployments.
Example: Automatically back up logs every night:
Practical Use Cases
Here are some common real-world scenarios:
1. Check disk space remotely:
2. Restart a service remotely:
3. Automate updates on multiple servers:
Real-life analogy
For running commands remotely: It's like sending a remote-controlled robot to your friend's house to check if the lights are on, then the robot comes back with the report. For multiple servers: It's like being the conductor of an orchestra: you don't need to touch every instrument yourself — you just give commands and the instruments (servers) play along. With this, you now know how to log in securely using SSH, set up passwordless login with keys, transfer files using scp or sftp, and run commands or scripts remotely. This is basically the foundation for remote system management, server automation, and secure network administration.