title: using NAPALM to connect to Cisco Router using SSH Key not working
body: <p>im trying to get netbox to get configs using NAPALM, but even the basic connection using napalm isnt working, always errors around the key file, which we need to use (cannot use password).</p>
  <p>napalm==3.4.1<br>
  python=3.8</p>
  <p>referred to the documentation at <a href="https://napalm.readthedocs.io/en/latest/support/" rel="nofollow noreferrer">https://napalm.readthedocs.io/en/latest/support/</a> for use of arguments</p>
  <p>I can directly SSH to the router using the key in ~/.ssh/ for the user netbox</p>
  <pre><code>netbox@netbox:~/.ssh$ ssh -c aes128-cbc netbox@172.1.1.1
  The authenticity of host '172.1.1.1 (172.1.1.1)' can't be established.
  RSA key fingerprint is SHA256:&lt;fingerprinthere&gt;.
  Are you sure you want to continue connecting (yes/no)? yes
  Warning: Permanently added '172.1.1.1' (RSA) to the list of known hosts.
  PHC-SW01&gt;
  </code></pre>
  <h2>Prompts for password and fails</h2>
  <p><strong>napalm --user netbox --vendor ios --optional_args 'use_keys=true, secret=passwordhere' --debug 172.1.1.1 call get_facts</strong></p>
  <pre><code>/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
    warnings.warn(
  /usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
    warnings.warn(
  Enter password:
  2022-08-24 13:03:01,926 - napalm - DEBUG - Starting napalm's debugging tool
  2022-08-24 13:03:01,926 - napalm - DEBUG - Gathering napalm packages
  2022-08-24 13:03:01,926 - napalm - DEBUG - napalm==3.4.1
  2022-08-24 13:03:01,926 - napalm - DEBUG - get_network_driver - Calling with args: ('ios',), {}
  2022-08-24 13:03:01,927 - napalm - DEBUG - get_network_driver - Successful
  Traceback (most recent call last):
    File &quot;/usr/local/bin/napalm&quot;, line 8, in &lt;module&gt;
      sys.exit(main())
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py&quot;, line 308, in main
      run_tests(args)
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py&quot;, line 269, in run_tests
      optional_args = helpers.parse_optional_args(args.optional_args)
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/helpers.py&quot;, line 131, in parse_optional_args
      return {
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/helpers.py&quot;, line 132, in &lt;dictcomp&gt;
      x.split(&quot;=&quot;)[0]: ast.literal_eval(x.split(&quot;=&quot;)[1])
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 99, in literal_eval
      return _convert(node_or_string)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 98, in _convert
      return _convert_signed_num(node)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 75, in _convert_signed_num
      return _convert_num(node)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 66, in _convert_num
      _raise_malformed_node(node)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 63, in _raise_malformed_node
      raise ValueError(f'malformed node or string: {node!r}')
  ValueError: malformed node or string: &lt;_ast.Name object at 0x7fa719a35af0&gt;
  </code></pre>
  <p><strong>napalm --user netbox --password '' --vendor ios --optional_args 'use_keys=true, secret=passwordhere' --debug 172.1.1.1 call get_facts</strong></p>
  <pre><code>  warnings.warn(
  /usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
    warnings.warn(
  2022-08-24 13:05:13,330 - napalm - DEBUG - Starting napalm's debugging tool
  2022-08-24 13:05:13,330 - napalm - DEBUG - Gathering napalm packages
  2022-08-24 13:05:13,331 - napalm - DEBUG - napalm==3.4.1
  2022-08-24 13:05:13,331 - napalm - DEBUG - get_network_driver - Calling with args: ('ios',), {}
  2022-08-24 13:05:13,331 - napalm - DEBUG - get_network_driver - Successful
  Traceback (most recent call last):
    File &quot;/usr/local/bin/napalm&quot;, line 8, in &lt;module&gt;
      sys.exit(main())
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py&quot;, line 308, in main
      run_tests(args)
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py&quot;, line 269, in run_tests
      optional_args = helpers.parse_optional_args(args.optional_args)
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/helpers.py&quot;, line 131, in parse_optional_args
      return {
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/helpers.py&quot;, line 132, in &lt;dictcomp&gt;
      x.split(&quot;=&quot;)[0]: ast.literal_eval(x.split(&quot;=&quot;)[1])
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 99, in literal_eval
      return _convert(node_or_string)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 98, in _convert
      return _convert_signed_num(node)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 75, in _convert_signed_num
      return _convert_num(node)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 66, in _convert_num
      _raise_malformed_node(node)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 63, in _raise_malformed_node
      raise ValueError(f'malformed node or string: {node!r}')
  ValueError: malformed node or string: &lt;_ast.Name object at 0x7f86f4974b80&gt;
  </code></pre>
  <p><strong>napalm --user netbox --vendor ios --optional_args 'alt_host_keys=True, alt_key_file=/home/netbox/.ssh/id_rsa' --debug 172.1.1.1 call get_facts</strong></p>
  <ul>
  <li>Prompts for password, when entered gives below.. shouldnt need password when keyfile is used.</li>
  </ul>
  <pre><code>/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
    warnings.warn(
  /usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
    warnings.warn(
  Enter password:
  2022-08-24 13:14:59,741 - napalm - DEBUG - Starting napalm's debugging tool
  2022-08-24 13:14:59,741 - napalm - DEBUG - Gathering napalm packages
  2022-08-24 13:14:59,741 - napalm - DEBUG - napalm==3.4.1
  2022-08-24 13:14:59,741 - napalm - DEBUG - get_network_driver - Calling with args: ('ios',), {}
  2022-08-24 13:14:59,742 - napalm - DEBUG - get_network_driver - Successful
  Traceback (most recent call last):
    File &quot;/usr/local/bin/napalm&quot;, line 8, in &lt;module&gt;
      sys.exit(main())
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py&quot;, line 308, in main
      run_tests(args)
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py&quot;, line 269, in run_tests
      optional_args = helpers.parse_optional_args(args.optional_args)
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/helpers.py&quot;, line 131, in parse_optional_args
      return {
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/helpers.py&quot;, line 132, in &lt;dictcomp&gt;
      x.split(&quot;=&quot;)[0]: ast.literal_eval(x.split(&quot;=&quot;)[1])
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 59, in literal_eval
      node_or_string = parse(node_or_string, mode='eval')
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 47, in parse
      return compile(source, filename, mode, flags,
    File &quot;&lt;unknown&gt;&quot;, line 1
      /home/netbox/.ssh/id_rsa
      ^
  SyntaxError: invalid syntax
  </code></pre>
  <p><strong>napalm --user netbox --vendor ios --optional_args &quot;hostkey_verify=False, look_for_keys=true, key_file=~/.ssh/id_rsa&quot; --debug  172.1.1.1 call get_facts</strong></p>
  <pre><code>/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
    warnings.warn(
  /usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
    warnings.warn(
  Enter password:
  2022-08-24 13:18:37,500 - napalm - DEBUG - Starting napalm's debugging tool
  2022-08-24 13:18:37,501 - napalm - DEBUG - Gathering napalm packages
  2022-08-24 13:18:37,501 - napalm - DEBUG - napalm==3.4.1
  2022-08-24 13:18:37,501 - napalm - DEBUG - get_network_driver - Calling with args: ('ios',), {}
  2022-08-24 13:18:37,501 - napalm - DEBUG - get_network_driver - Successful
  Traceback (most recent call last):
    File &quot;/usr/local/bin/napalm&quot;, line 8, in &lt;module&gt;
      sys.exit(main())
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py&quot;, line 308, in main
      run_tests(args)
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/cl_napalm.py&quot;, line 269, in run_tests
      optional_args = helpers.parse_optional_args(args.optional_args)
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/helpers.py&quot;, line 131, in parse_optional_args
      return {
    File &quot;/usr/local/lib/python3.8/dist-packages/napalm/base/clitools/helpers.py&quot;, line 132, in &lt;dictcomp&gt;
      x.split(&quot;=&quot;)[0]: ast.literal_eval(x.split(&quot;=&quot;)[1])
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 99, in literal_eval
      return _convert(node_or_string)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 98, in _convert
      return _convert_signed_num(node)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 75, in _convert_signed_num
      return _convert_num(node)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 66, in _convert_num
      _raise_malformed_node(node)
    File &quot;/usr/lib/python3.8/ast.py&quot;, line 63, in _raise_malformed_node
      raise ValueError(f'malformed node or string: {node!r}')
  ValueError: malformed node or string: &lt;_ast.Name object at 0x7ff3a5c5e6d0&gt;
  
  </code></pre>
  <p>If i specify <strong>--password ''</strong> it doesnt prompt for the password.
  If i use &quot;alt_key_file&quot; or &quot;key_file&quot; always has the same error:
  SyntaxError: invalid syntax</p>
  <p>running napalm as user 'netbox' accessing the keyfile should work.</p>
  <p>Update:
  tried putting quotes within quotes re: <a href="https://github.com/napalm-automation/napalm-base/issues/309#issuecomment-461185980" rel="nofollow noreferrer">https://github.com/napalm-automation/napalm-base/issues/309#issuecomment-461185980</a>
  but didnt work</p>
  <pre><code>--optional_args &quot;hostkey_verify=False, look_for_keys=true, key_file='~/.ssh/id_rsa'&quot;
  </code></pre>