# Netcommon.cli\_command using ssh keys

**URL:** <https://forum.ansible.com/t/netcommon-cli-command-using-ssh-keys/7350>\
**Category:** Get Help\
**Tags:** cisco, ssh, ansible-core, network\
**Created:** [July 18, 2024, 8:48pm UTC](https://forum.ansible.com/t/netcommon-cli-command-using-ssh-keys/7350 "2024-07-18T20:48:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgoulet00](https://avatars.discourse-cdn.com/v4/letter/b/6bbea6/32.png) [@bgoulet00](https://forum.ansible.com/u/bgoulet00)\
**Post date:** [July 18, 2024, 8:48pm UTC](https://forum.ansible.com/t/netcommon-cli-command-using-ssh-keys/7350/1 "2024-07-18T20:48:57Z")

</div>

i know the username and private key are good as i use them to connect to the same target in a terminal emulator. i am not able to get this working with ansible though.

here are the vars from my host file

```auto
vars:
    ansible_user: "admin"
    ansible_private_key_file: "filename.pem"
    ansible_become: false
    ansible_host_key_checking: false
    ansible_connection: network_cli
    ansible_network_os: cisco.ios.ios

```

and one simple task

```auto
  - name: get show run
    ansible.netcommon.cli_command:
      command: "show running-config"
    register: results

```

and finally the output. its actually crying about a public key but i don’t’ understand that and haven’t had any luck in my internet searching.  
this is probably simple but i’m a network guy, not a linux guy

```auto
TASK [get show run] ***********************************************************************************************************************************************************************
task path: /home/brian.goulet/ISE-test.yml:46
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
The full traceback is:
  File "/home/brian.goulet/.ansible/collections/ansible_collections/ansible/netcommon/plugins/modules/cli_command.py", line 171, in main
    response = connection.get(**module.params)
  File "/opt/ansible/venv/ansible8.0/lib64/python3.9/site-packages/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [10.22.5.240]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "answer": null,
            "check_all": false,
            "command": "show running-config",
            "newline": true,
            "prompt": null,
            "sendonly": false
        }
    }
}

MSG:

ssh connection failed: Failed to authenticate public key: Access denied for 'publickey'. Authentication that can continue: publickey

```

---

<div class="post-metadata">

**Author:** ![bgoulet00](https://avatars.discourse-cdn.com/v4/letter/b/6bbea6/32.png) [@bgoulet00](https://forum.ansible.com/u/bgoulet00)\
**Post date:** [July 24, 2024, 7:48pm UTC](https://forum.ansible.com/t/netcommon-cli-command-using-ssh-keys/7350/2 "2024-07-24T19:48:10Z")

</div>

nobody knows what the issue is here?

---

<div class="post-metadata">

**Author:** ![Jonathan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jonathan/32/4215_2.png) [@Jonathan](https://forum.ansible.com/u/Jonathan)\
**Post date:** [July 27, 2024, 6:15pm UTC](https://forum.ansible.com/t/netcommon-cli-command-using-ssh-keys/7350/3 "2024-07-27T18:15:24Z")

</div>

I’m having the same issue here. I had mine working a few days ago, but due to (other circumstances) I had to rebuild and now everything I had configured stopped working.

---

<div class="post-metadata">

**Author:** ![bgoulet00](https://avatars.discourse-cdn.com/v4/letter/b/6bbea6/32.png) [@bgoulet00](https://forum.ansible.com/u/bgoulet00)\
**Post date:** [July 30, 2024, 7:58pm UTC](https://forum.ansible.com/t/netcommon-cli-command-using-ssh-keys/7350/4 "2024-07-30T19:58:48Z")

</div>

my issue is resolved

1. during testing i found i was not able to dirrect ssh to anything from the linux box, even hosts ansible could connect to. my linux sysadmin fixed something in the background. i have no details on the fix
2. after item 1 was resolved it was discovered the username being used was incorrect. big fat human error

in the course of researching, i did also find this. it ended up not being my issue but i’ll leave it here for anyone else stumbling on this post that might be running older packages. the bug submission and fix was nearly 4 years ago.

[https://github.com/ansible-collections/ansible.netcommon/issues/168](https://github.com/ansible-collections/ansible.netcommon/issues/168)
