V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
SharkIng
V2EX  ›  问与答

有没什么办法能够做到/etc/hosts 和 ~/.ssh/config 同步?

  •  
  •   SharkIng · Aug 30, 2016 · 2302 views
    This topic created in 3528 days ago, the information mentioned may be changed or developed.

    /etc/hosts 或 本地的 DNS (类似 dnsmasq 等),以下统一称为 hosts ~/.ssh/config 文件,以下统称 ssh

    现在在 ssh 上配置了几个服务器的 ssh 登陆对应,可以用例如( ssh ) server1.linode , server2.digitalocean 之類的 ssh 進去 但是有些測試機等的需要有個網頁支持,所以想用例如 https://server1.linode:8080/ 之类的网址进入。想到的办法就是改 hosts 。可是如果每个 VPS 都要这样添加一遍的话也的确不是很方便,那么有什么办法能够做到 hosts 文件和 ssh config 同步么?添加 VPS 到一个地方,第二个地方就可以生效

    5 replies    2016-08-30 23:52:54 +08:00
    ITOutsider
        1
    ITOutsider  
       Aug 30, 2016 via iPhone
    买域名
    SharkIng
        2
    SharkIng  
    OP
       Aug 30, 2016
    @ITOutsider 我的 VPS 的确有个域名,但是这样做为了就是在电脑上输入的短一些而已。
    hack
        3
    hack  
       Aug 30, 2016 via Android
    puppet
    icetomoyo
        4
    icetomoyo  
       Aug 30, 2016
    不就是写个监控脚本的事儿么。。
    DravenJohnson
        5
    DravenJohnson  
       Aug 30, 2016
    awk '{if ($1=="Host") {host=$2} else if ($1=="HostName") {hostname=$2} else if ($1=="Port") {print hostname " " host}}' $HOME/.ssh/conf/*.conf >> /etc/hosts
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5261 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 64ms · UTC 01:12 · PVG 09:12 · LAX 18:12 · JFK 21:12
    ♥ Do have faith in what you're doing.