1
0
mirror of https://github.com/rancher/os.git synced 2025-09-10 19:20:55 +00:00

Support to configure ssh port and listen address

This commit is contained in:
niusmallnan
2018-03-05 14:49:52 +08:00
committed by niusmallnan
parent 204011e401
commit 67961c9349
2 changed files with 17 additions and 6 deletions

View File

@@ -86,7 +86,7 @@ func consoleInitFunc() error {
log.Error(err) log.Error(err)
} }
if err := modifySshdConfig(); err != nil { if err := modifySshdConfig(cfg); err != nil {
log.Error(err) log.Error(err)
} }
@@ -242,19 +242,28 @@ func writeRespawn(user string, sshd, recovery bool) error {
return ioutil.WriteFile("/etc/respawn.conf", []byte(respawn), 0644) return ioutil.WriteFile("/etc/respawn.conf", []byte(respawn), 0644)
} }
func modifySshdConfig() error { func modifySshdConfig(cfg *config.CloudConfig) error {
sshdConfig, err := ioutil.ReadFile("/etc/ssh/sshd_config") sshdConfig, err := ioutil.ReadFile("/etc/ssh/sshd_config")
if err != nil { if err != nil {
return err return err
} }
sshdConfigString := string(sshdConfig) sshdConfigString := string(sshdConfig)
for _, item := range []string{ modifiedLines := []string{
"UseDNS no", "UseDNS no",
"PermitRootLogin no", "PermitRootLogin no",
"ServerKeyBits 2048", "ServerKeyBits 2048",
"AllowGroups docker", "AllowGroups docker",
} { }
if cfg.Rancher.SSH.Port > 0 && cfg.Rancher.SSH.Port < 65355 {
modifiedLines = append(modifiedLines, fmt.Sprintf("Port %d", cfg.Rancher.SSH.Port))
}
if cfg.Rancher.SSH.ListenAddress != "" {
modifiedLines = append(modifiedLines, fmt.Sprintf("ListenAddress %s", cfg.Rancher.SSH.ListenAddress))
}
for _, item := range modifiedLines {
match, err := regexp.Match("^"+item, sshdConfig) match, err := regexp.Match("^"+item, sshdConfig)
if err != nil { if err != nil {
return err return err

View File

@@ -184,6 +184,8 @@ type DockerConfig struct {
type SSHConfig struct { type SSHConfig struct {
Keys map[string]string `yaml:"keys,omitempty"` Keys map[string]string `yaml:"keys,omitempty"`
Daemon bool `yaml:"daemon,omitempty"` Daemon bool `yaml:"daemon,omitempty"`
Port int `yaml:"port,omitempty"`
ListenAddress string `yaml:"listen_address,omitempty"`
} }
type StateConfig struct { type StateConfig struct {