/goshen

SSH Config Parser written in Go

Primary LanguageGo

Create a new config instance

config := goshen.NewSshConfig("~/.ssh/config")

Matching a host

Once you've created an instance of an SSH config, you can search for hosts using the MatchHost method.

Sample SSH config

Host server-1
  HostName server-1.example.com
  User user
  Port 22
  IdentityFile ~/.ssh/example_rsa
  LogLevel FATAL

Host server-2*
  HostName server-2.example.com
  User user
  Port 22
  IdentityFile ~/.ssh/example_rsa
  LogLevel FATAL
// return the config for server-2 with searching for server-2-web
hostEntry := config.MatchHost("server-2-web")

fmt.Println(hostEntry.HostName) // server-2.example.com

Saving the config

Calling save on the config instance will write the configuration to disk. If the outputPath argument is an empty string, the path given at the time goshen.NewSshConfig was called is used.

outputPath := ""
config.Save(outputPath)