diff --git a/internal/adapters/data/ssh_config_file/config_io.go b/internal/adapters/data/ssh_config_file/config_io.go index b5b8c5e..b4a820b 100644 --- a/internal/adapters/data/ssh_config_file/config_io.go +++ b/internal/adapters/data/ssh_config_file/config_io.go @@ -108,14 +108,13 @@ func (r *Repository) createTempFile(dir string) (string, error) { tempFileName := fmt.Sprintf("config%s%s", timestamp, TempSuffix) tempFilePath := filepath.Join(dir, tempFileName) - // Create the temp file - file, err := r.fileSystem.Create(tempFilePath) + // Create the temp file with explicit 0600 permissions + f, err := r.fileSystem.OpenFile(tempFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, SSHConfigPerms) if err != nil { return "", err } - - if err := file.Close(); err != nil { - r.logger.Warnf("failed to close temporary file %s: %v", tempFilePath, err) + if cerr := f.Close(); cerr != nil { + r.logger.Warnf("failed to close temporary file %s: %v", tempFilePath, cerr) } return tempFilePath, nil diff --git a/internal/adapters/data/ssh_config_file/crud.go b/internal/adapters/data/ssh_config_file/crud.go index 1bad485..7cea18c 100644 --- a/internal/adapters/data/ssh_config_file/crud.go +++ b/internal/adapters/data/ssh_config_file/crud.go @@ -97,7 +97,7 @@ func (r *Repository) createHostFromServer(server domain.Server) *ssh_config.Host {Str: server.Alias}, }, Nodes: make([]ssh_config.Node, 0), - LeadingSpace: 1, + LeadingSpace: 4, EOLComment: "Added by lazyssh", SpaceBeforeComment: strings.Repeat(" ", 4), }