请仔细查看该部分内容
自动补全主机名
bash-completion
在ubuntu中安装bash-completion工具,就可以实现一些基本命令的主机名自动补齐,比如ssh, rsync等.
1、deb包安装
sudo apt-get install bash-completion
2、编译安装
从官网下载最新的release版本,注意不要从git下载,有可能文件不全,导致安装失败.
修改~/.profile文件,写入如下内容: [[ $PS1 && -f /usr/local/share/bash-completion/bash_completion ]] &&
. /usr/local/share/bash-completion/bash_completion
3、开始编译安装
复制代码
./configure
make
make check # optional, requires dejagnu and tcllib
make install # as root
4、文件验证
查看是否存在该文件:/usr/local/share/bash-completion/bash_completion
注意:
补齐的主机名默认来源是~/.ssh/known_hosts文件
需要将/etc/ssh/ssh_config或者~/.ssh/config中的HashKnownHosts设置为no
自动登录主机
说明
关于自动登录主机的问题,wiki已经有很多相关的文章了,我这里介绍的方法,优缺点如下(输入token是必须的):
优点: 不需要本机生成无passphrase的私钥/公钥对,也不需要通过跳板机把公钥传到每台服务器上
缺点:
需要把跳板机上面的私钥复制到本地
打开终端,设置为"a login shell"模式
需要修改/创建的文件如下
~/master #用户放共享通道文件,例如
~/.profile #profile配置文件
~/.ssh/config #ssh配置文件
~/bin/ssh-add-pass # 判断ssh-agent,并自动输入passphrase
~/bin/passfile # 存放passphrase的密码文件
~/bin/ssh-attach # 判断ssh-agent,设置环境变量
注意:mac本的ssh-agent命令生成文件不在/tmp目录下,需要根据实际情况略做修改.
详细配置过程
配置本地的.profile文件(CentOS为.bash_profile),追加如下内容
复制代码
# Auto-passphrase
~/bin/ssh-add-pass ~/bin/passfile
eval $(~/bin/ssh-attach)
ssh配置文件:
位置: ~/.ssh/config
内容:
复制代码
Host *
User xxxx
Port 22
PreferredAuthentications publickey,password,gssapi-with-mic,hostbased,keyboard-interactive
StrictHostKeyChecking no
HashKnownHosts no</p>
<p>Host *.xxx.com
ServerAliveCountMax 6
ServerAliveInterval 300
ControlMaster auto
ControlPath ~/master/master-%h
ControlPersist yes
ssh-add-pass
复制代码
#!/bin/bash</p>
<p># reference:
# <a href="http://stackoverflow.com/questions/13033799/how-to-make-ssh-add-read-passphrase-from-a-file">http://stackoverflow.com/questions/13033799/how-to-make-ssh-add-read-passphrase-from-a-file</a> if [ $# -ne 1 ] ; then










