如何避免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:
-
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. -
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 yourknown_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:
-
Open (or create) the config file:
nano ~/.ssh/config
-
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!