Skip to content

Commit

Permalink
add a SSH_CONFIG_FILE option
Browse files Browse the repository at this point in the history
Sometimes it's useful to have a per-project SSH config. That config
might for example be generated by:

    export SSH_CONFIG_FILE=$(direnv_layout_dir)/ssh_config
    gcloud compute config-ssh --ssh-config-file="$SSH_CONFIG_FILE"

This option is a bit of a superset from all the other SSH_* env vars as
the ssh config file itself allows to set all of those other options.
  • Loading branch information
zimbatm committed Mar 31, 2020
1 parent 0630d6b commit 3f90aa8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Morph supports the following (optional) environment variables:
- `SSH_IDENTITY_FILE` the (local) path to the SSH private key file that should be used
- `SSH_USER` specifies the user that should be used to connect to the remote system
- `SSH_SKIP_HOST_KEY_CHECK` if set disables host key verification
- `SSH_CONFIG_FILE` allows to change the location of the ~/.ssh/config file

### Secrets

Expand Down
1 change: 1 addition & 0 deletions morph.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func createSSHContext() *ssh.SSHContext {
IdentityFile: os.Getenv("SSH_IDENTITY_FILE"),
DefaultUsername: os.Getenv("SSH_USER"),
SkipHostKeyCheck: os.Getenv("SSH_SKIP_HOST_KEY_CHECK") != "",
ConfigFile: os.Getenv("SSH_CONFIG_FILE"),
}
}

Expand Down
4 changes: 4 additions & 0 deletions ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type SSHContext struct {
AskForSudoPassword bool
DefaultUsername string
IdentityFile string
ConfigFile string
SkipHostKeyCheck bool
}

Expand Down Expand Up @@ -87,6 +88,9 @@ func (ctx *SSHContext) sshArgs(host Host, transfer *FileTransfer) (cmd string, a
args = append(args, "-i")
args = append(args, ctx.IdentityFile)
}
if ctx.ConfigFile != "" {
args = append(args, "-F", ctx.ConfigFile)
}
var hostAndDestination = host.GetTargetHost()
if transfer != nil {
args = append(args, transfer.Source)
Expand Down

0 comments on commit 3f90aa8

Please sign in to comment.