Должен ли я разрешить неизвестный ключ хоста при использовании SFTP?

5023
1.21 gigawatts

Я переключился с FTP с TLS на SFTP, и теперь при попытке подключения появляется диалоговое окно с сообщением Unknown Host Key для www.example.com. Затем представлены два варианта: Запретить и Разрешить.

Что это значит? Должен ли я выбрать Разрешить или Запретить?

4
Когда вы однажды навсегда приняли ключ, и однажды вы подключаетесь, появляется диалоговое окно с сообщением «ключ изменился и отличается от локального сохраненного ключа!» - тогда тебе стоит беспокоиться и быть осторожным. DanFromGermany 8 лет назад 0
@DanFromGermany Верно. Я использую Cyberduck, и он появляется каждый раз, когда я подключаюсь, чтобы загрузить или обновить каталог. Есть опция [] Всегда принимать, и вот где мне интересно, если я выберу эту опцию, она сообщит мне, когда она изменилась. Из того, что вы говорите, я могу выбрать всегда принимать, и он скажет мне, если он изменится от сохраненного значения. 1.21 gigawatts 8 лет назад 0
Обычно есть 3 варианта: 1. Хранить на постоянной основе и предупреждать об изменениях 2. Использовать только один раз 3. Отменить. Не существует опции «всегда принимать, даже если она меняется», потому что это противостоит всей логике аутентификации с открытым ключом, это было бы очень небезопасно. Так что да, будет большое предупреждение, когда сохраненный открытый ключ и открытый ключ сервера больше не будут совпадать. DanFromGermany 8 лет назад 1

2 ответа на вопрос

8
MariusMatutiae

SFTP is based upon SSH; hosts you connect to, just like with ssh, will provide you with a unique key which allows you to identify them. If you accept the key, any time in the future you connect to the same host the provided key will be checked against the one provided the first time (which is stored in $HOME/.ssh/known-hosts) and if the two match you will not be asked again; if instead the two keys do not match you will be warned of a possible attack (a Man In The Middle attack, MTIM).

So it is basically a security feature. SSH is based on TOFU (Trust On First Use). Which means you will have to accept the key after checking with the sysadmin that the presented key is indeed theirs, and then proceed to establish the communication.

EDIT:

How to check that we are being presented the right key, short of asking a (possibly non-existent) sysadmin? When you connect to a SSH/SFTP server for the first time, you are presented with something like the following:

 $ ssh me@remote The authenticity of host '[remote]:22 ([192.168.1.72]:22)' can't be established. ECDSA key fingerprint is b2:2d:52:1a:40:c2:f9:ca:9a:42:86:76:f4:0b:eb:84. Are you sure you want to continue connecting (yes/no)? 

Jot down the kind of fingerprint (ECDSA, above) and the fingerprint itself, b2:2d:52:1a:40:c2:f9:ca:9a:42:86:76:f4:0b:eb:84 above. Now go to the server(either physically or, in the case of a VPS, to the console), and, without any need to sudo su, go to /etc/ssh. You will see that there are many .pub files; one is ssh_host_ecdsa_key.pub (the type of fingerprint we were presented). Now issue this command:

 $ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub 

Its output must match the fingerprint you were offered above. If it does, you may now accept the key fingerprint in the ssh session, and proceed to ssh into the server.

There is no need to import anything from the server: ssh will take care of this for you.

Спасибо за отличное объяснение. Так что, если я подключаюсь к своей веб-хостинговой компании, должно быть место, где я могу найти этот ключ? Затем я загружаю его в каталог «известные хосты»? 1.21 gigawatts 8 лет назад 0
@ 1.21gigawatts Пожалуйста, смотрите мои изменения. MariusMatutiae 8 лет назад 1
1
Martin Prikryl

This is a redacted version of my guide Where do I get SSH host key fingerprint to authorize the server?


You should get an SSH host key fingerprint along with your credentials from the server administrator. Knowing the host key fingerprint and thus being able to verify it is an integral part of securing an SSH connection. It prevents man-in-the-middle attacks.

In the real world, most administrators do not provide the host key fingerprint.

If order to achieve the best security possible, you need to connect to the server using the most secure way available. Make any possible precautions to ensure a security of your local machine and a line to the server. For example if you need to obtain the host key to verify connection to the server from an external site (e.g. from home or a client), but you have a physical access to the server site, connect from the server site (e.g. your workplace).

You can also ask anyone with the physical access to the server (ideally the administrator). The host key is only one and hence the same for all users. Also note that the host key fingerprint is generated from a public key part of the host key only. So it is not secret and can be safely sent over an unencrypted (yet trusted) communication channels.

A special case is getting host key of a server, that you are an administrator of yourself, yet you do not have a direct secure line to connect through. This is common for virtual servers or servers in a cloud. In such case a server provider should have a specific solution. For example a specialized server in the same private network as your server, with publicly known host keys. You can connect to this specialized server and from it, securely connect to your server (e.g. using SSH terminal). As you are connecting within private network, you can safely trust any host key. Once connected to your server, acquire its host key. With that you can finally connect directly yet securely over a public network. Alternatively, the server provider can provide the host key via some administrative interface.

For example see my guides for:

Похожие вопросы