# Change the default sshd port

**URL:** <https://forums.suse.com/t/change-the-default-sshd-port/859>\
**Category:** RancherOS\
**Created:** [November 3, 2015, 11:23pm UTC](https://forums.suse.com/t/change-the-default-sshd-port/859 "2015-11-03T23:23:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lgcosta](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/lgcosta/32/463_2.png) [@lgcosta](https://forums.suse.com/u/lgcosta)\
**Post date:** [November 3, 2015, 11:23pm UTC](https://forums.suse.com/t/change-the-default-sshd-port/859/1 "2015-11-03T23:23:26Z")

</div>

I’m trying all possible ways, change the default port sshd, have tried to create the sshd\_config file, in cloud-config.yml file, but without success.

```
write_files:
- path: /etc/ssh/sshd_config
  permissions: 0600
  owner: root:root
  content: |
     Port 2222
     AuthorizedKeysFile	.ssh/authorized_keys
     UsePrivilegeSeparation sandbox # Default for new installations.
     ClientAliveInterval 180
     Subsystem	sftp	/usr/libexec/sftp-server
     UseDNS no
     PermitRootLogin no
     AllowGroups docker

```

I did not find information on how to do this via ros config. Can anyone help me ?

---

<div class="post-metadata">

**Author:** ![imikushin](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/imikushin/32/17_2.png) [@imikushin](https://forums.suse.com/u/imikushin)\
**Post date:** [November 9, 2015, 9:14am UTC](https://forums.suse.com/t/change-the-default-sshd-port/859/2 "2015-11-09T09:14:18Z")

</div>

@lgcosta I’m afraid, this is not currently possible, because sshd\_config is now rewritten by the console container start script _after_ cloud-init execute phase is run.

Maybe we’ll change it in v0.4.1: [https://github.com/rancher/os-images/pull/36](https://github.com/rancher/os-images/pull/36)

---

<div class="post-metadata">

**Author:** ![lgcosta](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/lgcosta/32/463_2.png) [@lgcosta](https://forums.suse.com/u/lgcosta)\
**Post date:** [November 10, 2015, 7:59pm UTC](https://forums.suse.com/t/change-the-default-sshd-port/859/3 "2015-11-10T19:59:33Z")

</div>

Thanks for reply @imikushin. As a palliative way, I’m doing as follows:

```
sudo mkdir -p /opt/rancher/bin
sudo bash -c 'cat <<EOF > /opt/rancher/bin/start.sh
#!/bin/bash
sudo sed -i "s/#Port 22/Port 2222/" /etc/ssh/sshd_config
sudo kill -HUP \$(ps ax |grep "sshd -D" | grep -v grep | awk "{ print $1 }")
EOF'
sudo chmod +x /opt/rancher/bin/start.sh

```

This is working 😉

---

<div class="post-metadata">

**Author:** ![lgcosta](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/lgcosta/32/463_2.png) [@lgcosta](https://forums.suse.com/u/lgcosta)\
**Post date:** [November 10, 2015, 9:52pm UTC](https://forums.suse.com/t/change-the-default-sshd-port/859/4 "2015-11-10T21:52:28Z")

</div>

best place in the cloud-config.yml 😄

```
write_files:
    - path: /opt/rancher/bin/start.sh
    permissions: "0755"
    owner: root
    content: |
      #!/bin/bash
      sudo sed -i "s/#Port 22/Port 2222/" /etc/ssh/sshd_config
      sudo kill -HUP \$(ps ax |grep "sshd -D" | grep -v grep | awk "{ print $1 }")
```

---

<div class="post-metadata">

**Author:** ![imikushin](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/imikushin/32/17_2.png) [@imikushin](https://forums.suse.com/u/imikushin)\
**Post date:** [November 11, 2015, 4:42am UTC](https://forums.suse.com/t/change-the-default-sshd-port/859/5 "2015-11-11T04:42:53Z")

</div>

That’s creative 😄

---

<div class="post-metadata">

**Author:** ![carloss](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@carloss](https://forums.suse.com/u/carloss)\
**Post date:** [November 23, 2015, 11:20am UTC](https://forums.suse.com/t/change-the-default-sshd-port/859/6 "2015-11-23T11:20:55Z")

</div>

Hello,

what is the current status of this in 0.4.1? Will the original OP’s solution work now?

Karel

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [November 23, 2015, 6:55pm UTC](https://forums.suse.com/t/change-the-default-sshd-port/859/7 "2015-11-23T18:55:13Z")

</div>

The issue mentioned above was merged before we cut v0.4.1, so it should be available. @imikushin Please let me know if I’m mistaken.

> <https://github.com/rancher/os-images/pull/36>

---

<div class="post-metadata">

**Author:** ![carloss](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@carloss](https://forums.suse.com/u/carloss)\
**Post date:** [November 23, 2015, 9:52pm UTC](https://forums.suse.com/t/change-the-default-sshd-port/859/8 "2015-11-23T21:52:13Z")

</div>

Yes, I can confirm it works now!

Just one thing:  
**permissions: 0600** will not be accepted! it has to be changed to **permissions: “0600”**

It is a mystery to me why so many cloud-init examples have missing quotes there. write\_files won’t work at all if those quotes are missing (spent 2 hours by debugging this!)

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [November 23, 2015, 10:17pm UTC](https://forums.suse.com/t/change-the-default-sshd-port/859/9 "2015-11-23T22:17:39Z")

</div>


