如何避免ssh登录别的机器的时候被询问Are you sure you want to continue connecting (yes/no/[fingerprint])

如何避免ssh的时候被询问

Are you sure you want to continue connecting (yes/no/[fingerprint])

就是修改/etc/ssh/ssh_config这个客户端ssh文件
添加如下的两行
Host *
StrictHostKeyChecking no

When you see the message “Are you sure you want to continue connecting (yes/no/[fingerprint])” while trying to connect to a remote server via SSH, it means that the server’s host key is not recognized by your local SSH client. To avoid this message in the future, you can take the following steps:

1. Manually Add the Host Key

You can manually add the server’s host key to your known_hosts file before connecting. Here’s how:

  1. Connect Once: Connect to the server, and when you see the prompt, type yes. This will add the server’s host key to your ~/.ssh/known_hosts file.

  2. Verify Host Key: If you want to do this without connecting, you can get the server’s host key fingerprint from the server administrator and manually add it.

    Use the following command on your local machine:

    ssh-keyscan -H <hostname_or_IP> >> ~/.ssh/known_hosts
    

    Replace <hostname_or_IP> with the server’s hostname or IP address. This command fetches the host key and appends it to your known_hosts file.

2. Disable Strict Host Key Checking (Not Recommended)

You can disable strict host key checking, but this is generally not recommended as it exposes you to security risks (like man-in-the-middle attacks). If you still want to do this for testing purposes, you can use:

ssh -o StrictHostKeyChecking=no <username>@<hostname_or_IP>

You can also set this option in your SSH configuration file (~/.ssh/config) for a specific host:

Host <hostname>
    StrictHostKeyChecking no

3. Create a Configuration File

If you connect to multiple servers frequently and want to manage settings easily, you can create or edit the SSH config file:

  1. Open (or create) the config file:

    nano ~/.ssh/config
    
  2. Add entries for your hosts:

    Host <hostname>
        User <username>
        StrictHostKeyChecking no
    

Important Note

While disabling strict host key checking might make it more convenient, it significantly reduces security. Always ensure you trust the server you’re connecting to and consider the risks involved in bypassing this security feature.

If you need more help or have specific use cases, feel free to ask!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值