rexec: Execute a command on a remote host


Introduction

rexec is a simple tool to execute a command on a remote host. It’s straightforward, but security caveats are important: rexec sends data in plaintext, so use it only in trusted networks or migrate to SSH for encryption.

Quickstart: practical commands

Here are a few pragmatic, minimal examples to get you started. Each example shows the exact syntax you’d type in a shell.

# Basic remote command
rexec --host remote.example.com ls -l

# Specify a remote username
rexec --username alice --host remote.example.com ps aux

# Redirect stdin from /dev/null on the remote host
rexec --noerr --host remote.example.com ls -l

# Specify the remote port
rexec --port 1234 --host remote.example.com ls -l

How rexec works (at a glance)

  • Rexec runs a single command on a remote host by opening a connection and executing the provided command string.
  • It does not establish an interactive shell by default; if you need continuous interaction, consider other tools or SSH with a pseudo-terminal.
  • All data, including credentials if you supply them, is transmitted in plain text.

Common pitfalls and gotchas

  • Security risk: Because rexec sends data in clear text, credentials and commands can be intercepted. Use SSH or VPN when possible.
  • Authentication differences: rexec supports a username flag, but it relies on the remote host’s configuration for access control. Misconfigured permissions can lead to access issues or security holes.
  • Port and host syntax: Mixing up —host and —port is a frequent error. Ensure you’re targeting the correct host and port, especially in non-standard environments.
  • No-host vs host: Forgetting the host flag can lead to unclear errors. Always specify —host (or -h) with the target.

When to choose rexec vs SSH

  • Use rexec only in trusted networks or on legacy systems where you need a quick, non-interactive remote command execution and encryption isn’t a concern.
  • Prefer SSH for modern setups: it provides encryption, authentication, and more robust security controls.

Alternatives and enhancements

  • SSH: ssh user@host ‘command’
  • SSH with keys: ssh -i ~/.ssh/id_rsa user@host ‘command’
  • For scripting remote commands with better security, consider SSH with a non-interactive setup or more advanced orchestration tools (Ansible, Salt, etc.).

TL;DR

rexec lets you run a command on a remote host, but it sends data in plaintext. Use SSH for encrypted communication and stronger security in real-world scenarios.

See Also