DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

Roy
Roy

Posted on

beawre the place where you put ssh include directive after

ๆˆ‘ไน‹ๅ‰็š„ ~/.ssh/config ไธญ็š„้…็ฝฎๆ˜ฏ

    Host *
        <directives>
        User root

    Include hosts-enabled/*.config
Enter fullscreen mode Exit fullscreen mode

hosts-enabled/gcp.config

Host gcp-1
    HostName 35.194.164.130
    User hi
Enter fullscreen mode Exit fullscreen mode

ๅฝ“ๆˆ‘่ฏ•ๅ›พ ssh gcp-1 ๆ—ถ๏ผŒๅ‘็Žฐๆ€ปๆ˜ฏไปฅ root ็”จๆˆท่€Œ้ž hi ็”จๆˆท็™ป้™†๏ผŒ้™ค้ž่ขซ่ฟ™ๆฎต้…็ฝฎๆŒชๅˆฐไธป้…็ฝฎๆ–‡ไปถ Host * ไธŠๆ–น

ๅŽŸๅ› ๆ˜ฏ Include directive may appear inside a Match or Host block to perform conditional inclusion. I had my Include statement trailing a Host directive so it was being included into that Host's config. ssh does not honor indention level as I supposed

ๅฆ‚ๆžœๆˆ‘ๅฐ†

    Host *
        <directives>
        User root
Enter fullscreen mode Exit fullscreen mode

ไฝœไธบ default.config ๅญ้…็ฝฎๆ–‡ไปถๆ”พๅœจ hosts-enabled ็›ฎๅฝ•ไธญ๏ผŒไธป้…็ฝฎๆ–‡ไปถๅชไฟ็•™Include hosts-enabled/*.config, gcp.config ไธญ็š„ User hi ๆŒ‡ไปคไป็„ถไธไผš็”Ÿๆ•ˆ๏ผŒๆŠŠ default.config ไธญ็š„ User root ๆŒ‡ไปคๅˆ ้™คๅฐฑๆญฃๅธธไบ†๏ผŒๆ นๆฎ man page

For each parameter, the first obtained value will be used. The configuration files contain sections separated by Host specifications, and that section is only applied for hosts that match one of the patterns given in the specification. The matched host name is usually the one given on the command line (see the CanonicalizeHostname option for exceptions).

Since the first obtained value for each parameter is used, more host-specific declarations should be given near the beginning of the file, and general defaults at the end.

ๆ นๆฎๅญ—ๆฏ้กบๅบ๏ผŒdefault.config ไธญ็š„้…็ฝฎไผšๆฏ” gcp.config ไธญ็š„้…็ฝฎๅ…ˆๅŠ ่ฝฝ

ๅฝ“ๆˆ‘ๆŠŠ Include ๆŒ‡ไปคๆ”พๅœจไธ€ไธช ๅธฆๆœ‰ HostName ็š„ host block ไน‹ๅŽๆ—ถ๏ผŒ่ฏ•ๅ›พ็™ป้™†ไธ€ๅฐไธปๆœบ็”š่‡ณไผšๆŠฅ้”™

ssh: Could not resolve hostname gcp-1: Temporary failure in name resolution

่ฟ™ๆ˜ฏๅ› ไธบๅ‰้ข็š„ HostName ๆŒ‡ไปค่ฆ†็›–ไบ†ๅŽ้ขๆ‰€ๆœ‰็š„ HostName ๆŒ‡ไปค

ๆ‰€ไปฅ Include ๆŒ‡ไปคๆœ€ๅฅฝๅŒ…ๅซๅœจๆ‰€ๆœ‰ Host ๆŒ‡ไปคไน‹ๅ‰๏ผŒๆˆ–่€…
You can leave the Include statement at the end of the file if you precede it with Match all. This terminates the previous Host/Match, and then conditionally always includes the file(s). So, the file would end with:

Match all
Include config.d/*
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Classic DEV Post

brain computer interface

Experimenting with brain-computer interfaces in JavaScript