Skip to content

Instantly share code, notes, and snippets.

@darthfork
Created September 1, 2025 19:03
Show Gist options
  • Select an option

  • Save darthfork/fae0c72adad58c08155bee170060f41d to your computer and use it in GitHub Desktop.

Select an option

Save darthfork/fae0c72adad58c08155bee170060f41d to your computer and use it in GitHub Desktop.
SSH config for passing secrets between host machine and virtual machine

Pass Secrets over SSH

To pass secrets over ssh config, follow the instructions below

Host machine config

On your host machine create an ssh config for your virtual machine in ~/.ssh/config as follows, and list the secrets you want to share using SendEnv

Host dev
    HostName <IP Address>
    User abhishekrai
    IdentityFile ~/.ssh/id_rsa
    SetEnv TERM="tmux-256color"
    SendEnv AWS_ACCESS_KEY_ID
    SendEnv AWS_ACCOUNT_NUMBER
    SendEnv AWS_SECRET_ACCESS_KEY
    SendEnv GITHUB_USERNAME
    SendEnv GITHUB_TOKEN
    SendEnv DOCKERHUB_USERNAME
    SendEnv DOCKERHUB_TOKEN

Virtual machine config

Configure your virtual machine's sshd to receive the secrets from host machine by adding a config file in /etc/ssh/sshd_config.d/variables.conf as follows

AcceptEnv AWS_ACCESS_KEY_ID
AcceptEnv AWS_ACCOUNT_NUMBER
AcceptEnv AWS_SECRET_ACCESS_KEY
AcceptEnv GITHUB_USERNAME
AcceptEnv GITHUB_TOKEN
AcceptEnv DOCKERHUB_USERNAME
AcceptEnv DOCKERHUB_TOKEN

Then restart your machine's ssh sudo systemctl restart sshd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment