How to point ssh to config file

Viewed 15209

I just switched local systems so I have to get back into a server again using the ssh keys. I usually use ssh david@server to get in. But since I have switched to the new machine the only way I can get into the server is ssh -i path/to/id_rsa_server david@0.0.0.0 which points to the private key on my machine.

Now I already have a config file set up in the .ssh folder which I copied over from the last machine. The file looks as such:

Host server
    Hostname 0.0.0.0
    User david
    IdentityFile ~/.ssh/id_rsa_server

How do I get the ssh system to recognize the config file again?

1 Answers

Normally ssh will get its configuration from ~/.ssh/config or globally from /etc/ssh/config.

To test:

  1. Use -v flag with ssh to see if your config file is loaded. As comments suggest you can increase verbosity with additional vs like -vvv.
user@pc:~$ ssh -v server
OpenSSH_8.2p1 Ubuntu-4, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/user/.ssh/config
debug1: /home/user/.ssh/config line 1: Applying options for server
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
  1. Check owner and permissions on .ssh/config. Directory permissions should be 700, and check ownership. It is possible step 1 will give hints.
user@pc:~$ ls -ld --  .ssh*/
drwx------ 2 user user 4096 May 25 23:05 .ssh/
user@pc:~$ ls -la .ssh/config
-rw-rw-r-- 1 user user 39 May 25 23:05 .ssh/config
  1. Launch ssh with -F <path-to-config> and see if there are issues.
user@pc:~$ ssh -v -F ~/.ssh/config

The items above should confirm permissions, paths, and file locations.

Related