Macos – /.ssh/known_hosts file does not exist? (Mac)

macossshterminal

I am trying to connect to a server via SSH in Terminal. I am able to connect to the server but during the process it asks me "Are you sure you want to continue connecting (yes/no)?"

I type "yes"

I then get a message that says

"Failed to add the host to the list of known hosts
(User/username/.ssh/known_hosts)"

After that I tried to open and clean out the known_hosts file, but I get a message that says

"The file /Users/username/.ssh/known_hosts does not exist."

Do I need to create the known_hosts file? I thought this would happen automatically when I connected to the server?

Best Answer

The article Failed to add the host to the list of known hosts has this advice :

Check directory permissions

The ssh client needs to be able to write to files in the .ssh directory :

ls -ld ~/.ssh

If the permissions aren't correct then run this to fix them:

chmod 0700 ~/.ssh

Check file permissions

Check if the files in the .ssh directory have read-write permissions :

ls -l ~/.ssh

If they don't, run :

chmod 0600 ~/.ssh/*

Remove ACL flags

If the ssh client still cannot write to the folder, one needs to clear the ACL flags :

chmod -R -a# 0 ~/.ssh
Related Question