I have added the following line (with a different IP) into the /etc/hosts
file:
192.168.0.4 my_pc
Likewise the ~/.ssh/config
file has the following entry in it:
Host 192.168.0.*
IdentityFile ~/id_rsa
Sending a ping
to my_pc
, sends a ping to 192.168.0.4
as intended. I can also ssh into the machine using ssh user@192.168.0.4
. If I try ssh user@my_pc
, the authentication fails as the key is not used.
How to set up ssh so that /etc/hosts
is recognised?
I know that a host name can be done in ~/.ssh/config
however is there a way to keep the host name out of that file and have it match the IP to /etc/hosts
?
Best Answer
You don't need to use
/etc/hosts
file to connectuser@my-pc
. Add following lines to~/.ssh/config
So now when you just type
ssh my-pc
it will connect to john@192.168.0.4I have made to myself a little script to make adding new hosts as fast as possible, you may use it aswell ;)