dcg

ssh

remote.ssh

Protects against destructive SSH operations like remote command execution and key management.

  • 6blocking rules
  • 9safe patterns
  • 2Critical
  • 2High
  • 2Medium
~/.config/dcg/config.toml
[packs]
enabled = ["remote.ssh"]

Evaluated when a command contains ssh, ssh-keygen, ssh-keyscan.

Blocking rules

Each rule ID is remote.ssh:<name>. Use it in allowlists and [policy.rules].

  1. ssh-remote-rm-rf

    Critical

    SSH remote execution contains destructive rm -rf command.

    Explanation
    Executing rm -rf on a remote system via SSH can cause irreversible data loss. Remote systems often have different directory structures and you may not have the same safety mechanisms in place. Safer alternatives: - SSH in and run commands interactively with confirmation - Use --dry-run or preview flags when available - Ensure backups exist on the remote system
  2. ssh-remote-sudo-rm

    Critical

    SSH remote execution with sudo rm is high-risk.

    Explanation
    Executing sudo rm on a remote system bypasses normal permission restrictions and can delete system files. Combined with SSH, there's no interactive confirmation and errors may not be visible. Safer alternatives: - SSH in and run sudo commands interactively - Use mv to a backup location instead of rm - Implement proper cleanup scripts with safety checks
  3. ssh-remote-git-clean

    High

    SSH remote execution contains destructive git clean -f command.

    Explanation
    Running git clean -f on a remote server permanently removes untracked files. This might delete logs, uploads, or configuration files that were never committed to the repository. Safer alternatives: - Run git clean -n first to preview what would be deleted - Use .gitignore to protect important untracked files - Back up untracked files before cleaning
  4. ssh-remote-git-reset-hard

    High

    SSH remote execution contains destructive git reset --hard command.

    Explanation
    Running git reset --hard on a remote server discards all uncommitted changes. On production servers, this might destroy deployment state or configuration changes made directly on the server. Safer alternatives: - git stash on the remote first to save changes - Use git status remotely to check for uncommitted work - Consider proper deployment pipelines instead of direct remote git
  5. ssh-add-delete-all

    Medium

    ssh-add -d/-D removes identities from the SSH agent.

    Explanation
    Removing SSH identities from the agent will require re-authentication for subsequent connections. Using -D removes ALL identities, which may interrupt active sessions or scripts. Safer alternatives: - Use -d to remove specific keys rather than -D for all - List keys with ssh-add -l before removing - Re-add keys immediately if needed
  6. ssh-keygen-remove-host

    Medium

    ssh-keygen -R removes entries from known_hosts file.

    Explanation
    Removing entries from known_hosts weakens protection against man-in-the-middle attacks. The next connection will trust any key presented by the remote host. Safer alternatives: - Verify the new host key fingerprint before removing old entry - Use ssh-keyscan to preview the new key - Update entry rather than removing (add new key, then remove old)

Safe patterns

Checked first. A command that matches one is never blocked by this pack.

  • ssh-version
  • ssh-version-long
  • ssh-keygen-list
  • ssh-keygen-fingerprint
  • ssh-keyscan
  • ssh-add-list
  • ssh-agent
  • ssh-help
  • ssh-keygen-help