Remote Bash Editing: Tools and Workflows for DevOps
DevOps work happens on remote servers. Your bash editor needs to work seamlessly over SSH, whether you’re fixing production issues or developing automation.
This guide covers remote bash editing approaches. For local editor setup, see our bash editor guide.
Remote Editing Approaches
Three main strategies for editing bash files remotely:
- Terminal editors over SSH: vim, nano, micro
- Remote extensions: VS Code Remote SSH
- Local editing with sync: rsync, scp, SSHFS
Terminal Editors Over SSH
The classic approach—SSH in and edit directly.
Using Vim Over SSH
ssh production-server
vim /opt/app/scripts/deploy.sh
Advantages:
- Works everywhere
- No additional setup
- Low bandwidth
- Fast startup
Best practices:
# Use SSH config for quick access
# ~/.ssh/config
Host prod
HostName production.example.com
User deploy
IdentityFile ~/.ssh/prod-key
# Now just:
ssh prod
vim /path/to/script.sh
Handling Disconnections
Use tmux to preserve sessions:
ssh prod
tmux new -s editing
# Edit files, if disconnected:
ssh prod
tmux attach -t editing
# You're back where you left off
Quick Remote Edits
Edit a file without staying logged in:
# Open vim, make changes, exit
ssh prod "vim /etc/nginx/conf.d/app.conf"
VS Code Remote SSH
Full IDE features on remote servers.
Setup
Install the extension:
code --install-extension ms-vscode-remote.remote-ssh
Configure SSH hosts (VS Code reads ~/.ssh/config):
Host prod
HostName production.example.com
User deploy
IdentityFile ~/.ssh/prod-key
ForwardAgent yes
Connecting
Ctrl+Shift+P→ “Remote-SSH: Connect to Host”- Select host
- Wait for server setup (first time takes longer)
- Open folders and files normally
Remote Development Benefits
- Full IntelliSense: Reads remote filesystem
- Extensions run remotely: ShellCheck checks on the server
- Integrated terminal: Already connected
- Port forwarding: Access remote services locally
Configuration for Bash
settings.json for remote bash editing:
{
"remote.SSH.defaultExtensions": [
"timonwong.shellcheck",
"mads-kristensen.markdown-all-in-one"
],
"remote.SSH.connectTimeout": 60,
"[shellscript]": {
"editor.tabSize": 2
}
}
Limitations
- Resource usage: Installs VS Code server on remote
- Connectivity: Needs stable connection
- Security: Server runs code on your behalf
SSHFS: Mount Remote Filesystems
Edit remote files as if they’re local.
Installation
# macOS (via macFUSE)
brew install macfuse
brew install sshfs
# Ubuntu
sudo apt install sshfs
Mounting
# Mount remote directory
mkdir -p ~/mnt/prod
sshfs deploy@production:/opt/scripts ~/mnt/prod
# Edit with any local editor
code ~/mnt/prod/deploy.sh
vim ~/mnt/prod/config.sh
# Unmount when done
fusermount -u ~/mnt/prod # Linux
umount ~/mnt/prod # macOS
Advantages
- Use any local bash editor
- Full local tooling
- Works with GUI applications
Disadvantages
- Latency on saves
- Can be unstable
- Caching issues possible
Rsync Workflows
Sync files between local and remote.
Development Workflow
# Work locally
vim scripts/deploy.sh
# Sync to server
rsync -avz scripts/ prod:/opt/scripts/
# Test on server
ssh prod "/opt/scripts/deploy.sh"
# Sync back any changes
rsync -avz prod:/opt/scripts/ scripts/
Watch and Sync
Auto-sync on file changes:
# Using fswatch (macOS)
fswatch -o scripts/ | xargs -n1 -I{} rsync -avz scripts/ prod:/opt/scripts/
# Using inotifywait (Linux)
while inotifywait -r -e modify scripts/; do
rsync -avz scripts/ prod:/opt/scripts/
done
Comparing Remote Editing Approaches
| Approach | Latency | Setup | Offline Editing | Best For |
|---|---|---|---|---|
| SSH + vim | Low | None | No | Quick fixes |
| VS Code Remote | Medium | Easy | No | Development |
| SSHFS | Variable | Moderate | No | GUI editors |
| Rsync | None local | Easy | Yes | Iterative work |
Security Considerations
Remote editing involves security tradeoffs.
Best Practices
# Use SSH keys, not passwords
ssh-keygen -t ed25519 -C "work@company.com"
ssh-copy-id prod
# Limit key capabilities
# ~/.ssh/authorized_keys on server:
# command="/usr/bin/vim",no-port-forwarding ssh-ed25519 AAAA...
# Use SSH agent forwarding carefully
# Only to trusted servers
Host prod
ForwardAgent yes
Audit Trail
Log who edits what:
# Server-side logging
export PROMPT_COMMAND='echo "$(date "+%Y-%m-%d %H:%M:%S") $(whoami) $(pwd) $(history 1)" >> /var/log/shell-audit.log'
From Remote Editing to Remote Execution
Editing files remotely is necessary. But running commands from documentation is the real goal.
Traditional workflow:
- Read runbook on wiki
- SSH to server
- Open bash editor, or type commands manually
- Copy commands from documentation
- Execute and observe
This is error-prone and slow.
Stew: Remote Execution Made Simple
Stew runs your runbook commands over SSH. No manual copying.
# Server Maintenance
## Check disk space
```bash
ssh prod "df -h"
```
## Rotate logs
```bash
ssh prod "logrotate -f /etc/logrotate.conf"
```
## Verify services
```bash
ssh prod "systemctl status nginx"
```
Each cell executes with a click. Output is captured. Your remote bash work becomes executable documentation.
Join the waitlist and simplify remote operations.