codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐧

Linux & Bash

51 / 60 topics
39Advanced Scripting40Bash Arrays41Bash Associative Arrays42Advanced Functions43Advanced Script Debugging44Script Optimization45Automation with Scripts46Script Integration47Script Logging48Error Handling49Script Performance50Parallel Processing51Remote Execution52Configuration Management53Script Monitoring54Automation Tools55Continuous Integration56Script Deployment57Script Security58Script Audit59Optimization Tips60Advanced Debugging
Tutorials/Linux & Bash/Remote Execution
🐧Linux & Bash

Remote Execution

Updated 2026-05-15
10 min read

Remote Execution

Introduction

In the world of Linux and Bash scripting, executing commands or scripts on remote systems is a common task. This can be achieved using Secure Shell (SSH), which provides secure encrypted communications between two untrusted hosts over an insecure network. In this tutorial, we will explore how to execute scripts on remote systems using SSH.

Concept

SSH allows you to connect to a remote server and run commands as if you were sitting in front of the server's console. This is particularly useful for automating tasks across multiple servers or managing configurations remotely.

Key Concepts:

  1. SSH Client: The tool used to initiate an SSH connection.
  2. SSH Server: The service running on the remote machine that accepts connections.
  3. Authentication: Methods such as passwords, public key authentication, and Kerberos are used to verify user identities.
  4. Port: By default, SSH operates over port 22.

Examples

Basic Remote Command Execution

You can execute a single command on a remote server using the following syntax:

Terminal
Output
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        20G   15G  4.6G  78% /
tmpfs           938M     0  938M   0% /dev/shm

Executing a Script

To execute a script on a remote server, you can use the following approach:

  1. Copy the script to the remote server:
Terminal
$ scp local_script.sh user@example.com:/path/to/remote/directory/
  1. Execute the script remotely:
Terminal
$ ssh user@example.com "/path/to/remote/directory/local_script.sh"

Using SSH Keys for Authentication

For secure and passwordless authentication, you can use SSH keys:

  1. Generate an SSH key pair (if not already done):
Terminal
$ ssh-keygen -t rsa
  1. Copy the public key to the remote server:
Terminal
$ ssh-copy-id user@example.com
  1. Execute a command without entering a password:
Terminal
$ ssh user@example.com "echo 'Hello, World!'"

Using SSH with Port Forwarding

SSH can also be used to forward ports, which is useful for accessing services running on remote servers:

Terminal
$ ssh -L local_port:remote_host:remote_port user@example.com

For example, to forward port 8080 on your local machine to port 80 on a remote server:

Terminal
$ ssh -L 8080:example.com:80 user@example.com

Now, you can access the service running on example.com:80 by visiting http://localhost:8080 on your local machine.

What's Next?

In the next section, we will explore Configuration Management tools like Ansible and Puppet, which provide more advanced capabilities for managing configurations across multiple servers.

By mastering remote execution with SSH, you'll be well-equipped to automate tasks and manage systems efficiently in a Linux environment.


PreviousParallel ProcessingNext Configuration Management

Recommended Gear

Parallel ProcessingConfiguration Management