# Ansible SSH bastion host and changing SSH port

**URL:** <https://forum.ansible.com/t/ansible-ssh-bastion-host-and-changing-ssh-port/29729>\
**Category:** Ansible Project\
**Created:** [February 21, 2019, 4:12am UTC](https://forum.ansible.com/t/ansible-ssh-bastion-host-and-changing-ssh-port/29729 "2019-02-21T04:12:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [February 21, 2019, 4:12am UTC](https://forum.ansible.com/t/ansible-ssh-bastion-host-and-changing-ssh-port/29729/1 "2019-02-21T04:12:30Z")

</div>

Hi,  
i got a question on how to change the SSH port via bastion host

So, the setup is this:  
ansible server (on ssh port 6701) —\> Bastion server (on ssh port 6701) → linux server (on ssh port 22)

i tried to add “ansible\_ssh=22” in the inventory file, but this will try to connect from “ansible server” to “Bastion server” on port 22  
If i tried to add “ansible\_ssh=6701” in the inventory file, this will try to connect from “ansible server” to “bastion server” on port 6701 (which is correct), but also will connect to “linux server” on port 6701. How do i change this last part to port 22 ?

Thank you!

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [February 21, 2019, 9:31am UTC](https://forum.ansible.com/t/ansible-ssh-bastion-host-and-changing-ssh-port/29729/2 "2019-02-21T09:31:40Z")

</div>

I assume "ansible server (on port 6701)" is the control machine. So  
the port which you access that is relevant for this story.  
While on the control machine (where your ansible, inventory, etc  
reside), you can use something like this in your inventory:

linux\_server ansible\_ssh\_common\_args='-o ProxyJump="bastionuser@bastion:6701"'

If several or all hosts require jumping through this bastion, you can  
add this to the group or all vars:

[need\_bastion]  
linux\_server  
linux\_server2  
linux\_server3  
[need\_bastion:vars]  
ansible\_ssh\_common\_args='-o ProxyJump="bastionuser@bastion:6701"'

Note that ProxyJump requires OpenSSH 7.2 or later. WIth earlier SSH  
versions you need to use ProxyCommand:

[https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies\_and\_Jump\_Hosts](https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Jump_Hosts)  
for more inspiration.

Dick
