---
name: ssh_config_write
kind: function
lang: go
domain: infra
version: "1.0.0"
purity: impure
signature: "func SSHConfigWrite(entries []SSHConfigEntry) error"
description: "Escribe entries a ~/.ssh/config con backup automatico del archivo previo."
tags: [ssh, config, write, remote, pendiente-usar]
uses_functions: [ssh_config_render_go_infra]
uses_types: [ssh_config_entry_go_infra]
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [fmt, os, path/filepath]
params:
  - name: entries
    desc: "lista de SSHConfigEntry a escribir en ~/.ssh/config"
output: "nil si la escritura fue exitosa"
tested: true
tests:
  - TestSSHConfigWrite_CreatesFileAndDir
  - TestSSHConfigWrite_BackupExisting
  - TestSSHConfigWrite_NoBackupWhenAbsent
  - TestSSHConfigWriteRead_Roundtrip
test_file_path: "functions/infra/ssh_config_write_test.go"
file_path: "functions/infra/ssh_config_write.go"
---

## Ejemplo

```go
entries, _ := SSHConfigRead()
entries, _ = SSHConfigAddEntry(entries, SSHConfigEntry{
    Alias: "prod", HostName: "10.0.0.1", User: "deploy",
})
if err := SSHConfigWrite(entries); err != nil {
    log.Fatal(err)
}
```

## Notas

Crea `~/.ssh/` con permisos 0700 si no existe. Hace backup a `~/.ssh/config.bak` antes de sobrescribir. El archivo resultante tiene permisos 0600 (solo lectura/escritura para el owner).
