ssh」カテゴリーアーカイブ




sshでホスト名や、serviceのデーモン名、manコマンドを補完する bash-completion のインストール




投稿日:

ホスト名が補完されるbash-completion をインストールしてみます。これがあれば、打ち間違えも押さえられるし、効率化にも繋がります。

インストール作業 # centOSの場合

パッケージインストール済みかを確認。
[html]# rpm -qa | grep bash-completion[/html]

ソースインストールを考慮し、コマンドでも確認。
[html]# complete[/html]

かなりの行数が表示されると入っています。
無ければインストールします。

レポジトリ確認
[html]# yum repolist | grep epel[/html]

無ければepelを追加しましょう。

インストール。
[html]# yum install bash-completion[/html]
パッケージをインストールすると、.bashrc等に記述を記載する必要はありません。 /etc/profile.d/ に設置してくれている。

一度ログアウトして再ログイン。

[html]# ssh <tab>[/html]

で、ホスト名が表示されていればOK.

sshの他にも、色々なサービスの引数に対応しています。第1引数、第2引数というようにコマンドによって、起動スクリプトの中身まで読んで補完をしてくれているようです。

ただし、補完しないコマンドも多数なので気をつけないと行けません。

補完の情報は以下で設定されている

/etc/bash_completion.d/ に格納のコマンドが対象です。

[html]
# ls /etc/bash_completion.d/
_subversion bind-utils cryptsetup gdb iproute2 mdadm perl rcs shadow util-linux
_yum bzip2 cvs getent iptables mkinitrd pkg-config redefine_filedir smartctl wireless-tools
_yum-utils chkconfig dd gpg lftp module-init-tools pm-utils rpcdebug sqlite3 xmllint
aspell configure dhclient gzip lsof mysqladmin postfix rpm ssh xmlwf
autoconf coreutils e2fsprogs iconv lvm net-tools procps rsync strace xorg-x11-server-utils
automake cpio findutils ifupdown make open-iscsi python service tar xsltproc
bash-builtins crontab gcc info man openssl quota-tools sh tcpdump yp-tools
[/html]

もし、何か付け足したい場合はここにbashファイルを置いて上げると補完対象になります。