fix: redirect the user to the home directory if dir is not set (#6085)

This was blocking SSH connections from being established if a dir
that wasn't created yet is set.
This commit is contained in:
Kyle Carberry 2023-02-07 14:28:41 -06:00 committed by GitHub
parent bde4ffebe5
commit f6effdb63e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -803,7 +803,11 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
cmd := exec.CommandContext(ctx, shell, args...)
cmd.Dir = metadata.Directory
if cmd.Dir == "" {
// If the metadata directory doesn't exist, we run the command
// in the users home directory.
_, err = os.Stat(cmd.Dir)
if cmd.Dir == "" || err != nil {
// Default to user home if a directory is not set.
homedir, err := userHomeDir()
if err != nil {