linux – 如何管理频繁访问的主机列表?

前端之家收集整理的这篇文章主要介绍了linux – 如何管理频繁访问的主机列表?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何快速选择并登录我需要通过ssh访问的多个主机?我正在构建一个类似下面的 shell脚本,它使用对话框从命令行显示主机菜单,但我很好奇是否有更好的方法.
  1. #!/bin/dash
  2. tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
  3. trap "rm -f $tempfile" 0 1 2 5 15
  4.  
  5. while [ 1 ]
  6. do
  7. dialog --menu "Select Host" 0 0 0 \
  8. "hostname1" "Host description 1" \
  9. "hostname2" "Host description 2" \
  10. "hostname3" "Host description 3" 2> $tempfile
  11.  
  12. HOSTNAME=`cat $tempfile`
  13.  
  14. if [ "x" = "x$HOSTNAME" ]; then
  15. break
  16. fi
  17.  
  18. ssh $HOSTNAME
  19. done

解决方法

我喜欢在我的客户机上的〜/ .ssh / config文件中设置每个主机的短名称.这是一个例子:
  1. Host host1
  2. HostName longhostname.mydomain.com
  3. User remoteuser
  4. IdentityFile ~/ssh-keys/id_rsa-my-keypair

这样我就可以输入“ssh host1”并立即登录.

猜你在找的Linux相关文章