大网数据广告活动
服务器运维问答

SSH: In private network how to access the remote machine from source machine without using ssh public key

· 52CE 我爱测

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 th…

问题原文

原帖链接 · CodeQuestor · CC BY-SA 4.0

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 omitted] 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 omitted] uname
Host key verification failed.

Is it possible to achieve the same with some options?

已采纳解答

原帖链接 · MLu · CC BY-SA 4.0

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:

  1. More secure is to provide the Ubuntu server's host key to your CodeBuild and store it to a known_hosts file where ssh can verify it. Make sure it's in the right path with the correct ownership and permissions.

  2. Less secure is to disable the check:

    ssh -o StrictHostKeyChecking=no {your-ubuntu-server}
    

Hope that helps :)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-02-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。