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

SSH known_hosts entry for port number and tunneling using @cert-authority

· 52CE 我爱测

I've set up SSH certificate authority on my server, including a signed host key with the applicable principals. I've set up my local known_hosts file to recognize the certificate authority and when I ssh directly into the host it…

问题原文

原帖链接 · James S · CC BY-SA 4.0

I've set up SSH certificate authority on my server, including a signed host key with the applicable principals. I've set up my local known_hosts file to recognize the certificate authority and when I ssh directly into the host it works fine. However, I've also set up a reverse tunnel on the host to SSH into it via a VM I have set up. I can't figure out how to get my SSH client to recognize it as a known host, despite an appropriate string in the signed host key. How do I sign the host key, or set up the known_hosts entry, to recognize the host when tunneling through a 3rd party?

This is the appropriate line from my client's known_hosts:

@cert-authority *.DOMAIN.us ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRd5kjlix8PN1SsQ...

Here's the ssh-keygen -L for the host key:

pi@ca51-1:~ $ ssh-keygen -L -f /etc/ssh/ssh_host_ecdsa_key-cert.pub 
/etc/ssh/ssh_host_ecdsa_key-cert.pub:
        Type: [email omitted] host certificate
        Public key: ECDSA-CERT SHA256:at+6J0W9S0BZj96YeJqtUCAAksUFu8P840ZCkVm9fb0
        Signing CA: RSA SHA256:AYPOCzb67UvUUIoULa3BgstmX1XIDP9+4bClTycMC9g
        Key ID: "ca51-1.in"
        Serial: 9
        Valid: forever
        Principals: 
                ca51-1.local
                ca51-1.in.DOMAIN.us
                [tunnel.in.DOMAIN.us]:10030
        Critical Options: (none)
        Extensions: (none)

When I try to connect to the server locally (ssh [email omitted]) I connect without any problems. (I just noticed that *.local isn't in my known_hosts file despite it working.)

Notice that I have the tunnel address:port as a principal ([tunnel.in.DOMAIN.us]:10030).

When I try to ssh into the server via that tunnel I receive an error:

ssh -p 10030 [email omitted]
key_cert_check_authority: invalid certificate
Certificate invalid: name is not a listed principal
The authenticity of host '[tunnel.in.awosome.us]:10030 ([138.68.10.xxx]:10030)' can't be established.
ECDSA key fingerprint is SHA256:at+6J0W9S0BZj96YeJqtUCAAksUFu8P840ZCkVm9fb0.

Here's some more debug from -v:

debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host certificate: [email omitted] SHA256:at+6J0W9S0BZj96YeJqtUCAAksUFu8P840ZCkVm9fb0, serial 9 ID "ca51-1.in" CA ssh-rsa SHA256:AYPOCzb67UvUUIoULa3BgstmX1XIDP9+4bClTycMC9g valid forever
debug1: checking without port identifier
debug1: Host 'tunnel.in.awosome.us' is known and matches the ECDSA-CERT host certificate.
debug1: Found CA key in /Users/jshannon/.ssh/known_hosts:31
key_cert_check_authority: invalid certificate
Certificate invalid: name is not a listed principal

To confirm that I hadn't made a mistake with known_hosts I copied out the key on line 31 (ssh-rsa ....), pasted it into a temp file, then ran ssh-keygen -l:

ssh-keygen -l -f temp_keys/key.pub 
2048 SHA256:AYPOCzb67UvUUIoULa3BgstmX1XIDP9+4bClTycMC9g AWOS (RSA)

I thought that maybe the host format in principals was incorrect, but if I accept the unknown host, I get its key added to known_hosts:

[tunnel.in.DOMAIN.us]:10030,[138.68.10.xxx]:10030 ecdsa-sha2-nistp256 AAAAE2VjZHNhLX

The first entry matches up with entry in principals, down to the format and port number.

I've tried several iterations of principals entries without success. Ideally I'd like to have a principals entry which locks the host down to a FQDN (tunnel.in.DOMAIN) and port, but I'd be OK any port on that machine. I also tried some asterisks in there.

已采纳解答

原帖链接 · Erik Huelsmann · CC BY-SA 4.0

Rather late to the game (5 years after the question), but I ran into this problem myself today and thought I'd document this for others running into it too. The answer is short, but the hints to it are rather obfuscated. The key part is:

debug1: Found CA key in /Users/jshannon/.ssh/known_hosts:31
key_cert_check_authority: invalid certificate
Certificate invalid: name is not a listed principal

The point OpenSSH is trying to make is that the name of the server you're using to connect (that is [tunnel.in.DOMAIN.us]:10030), should have been listed as a principal in the provided certificate - but isn't. Generating a certificate including this principal will solve the problem.

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

资料来源与适用范围

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

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

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