SSH: In private network how to access the remote machine from source machine without using ssh public key
I have AWS codebuild setup where want to access the EC2 ubuntu instance both are in same VPC and private subnet. Want to execute the command from codebuild to instance using SSH but getting below error, while trying to execute the command on the remote instance:
$ ssh -o 'PubkeyAuthentication no' [email protected] uname
Host key verification failed.
I also tried to create the .pem file and pasted the public key to the new pem file, changed its permission and used that. But no success.
$ssh -i "remote-instance.pem" [email protected] uname
Host key verification failed.
Is it possible to achieve the same with some options?
As you know the first time you ssh
to a remote host it asks you whether you'd like to store the remote host key to ~/.ssh/known_hosts
. Every time you access the remote host afterwards ssh
verifies received host key against ~/.ssh/known_hosts
.
However when ssh
runs in CodeBuild or some other non-interactive setup it can't ask whether to accept the remote key (because there's no one to ask in a non-interactive session) and to be on the safe side it fails with Host key verification failed
You've got two options how to fix it:
More secure is to provide the Ubuntu server's host key to your CodeBuild and store it to a
known_hosts
file wheressh
can verify it. Make sure it's in the right path with the correct ownership and permissions.-
Less secure is to disable the check:
ssh -o StrictHostKeyChecking=no {your-ubuntu-server}
Hope that helps :)
You do want PubkeyAuthentication which will be attempted by default, so do not specify "-o PubkeyAuthentication=no". The pem file referenced by "-i" should be the private key, not the public key. The public key will already be in place on your ubuntu server.