chkconfig --listコマンドはどのサービスがどのランレベルごとに起動するようになっているかどうかを一覧で見ることができます。
(chkconfig --listでランレベルごとに見れるサービスはスタンドアロン型サービス。スーパーデーモン型は見れません。というか私のvine4.2はxinetdがないね・・・)
また、サービスを引数に指定することができます。
# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
sshdがオンになっていたのでオフに変更します。
# chkconfig sshd off
もう一度確認
# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:off 4:off 5:off 6:off
今度はオンにします。
# chkconfig sshd on
確認。
# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
レベルを指定して変更
# chkconfig --level 2345 sshd off
確認。
chkconfig --list sshd
sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
このオン、オフはあくまでPC起動時の設定ね。
chkconfigでsshdをオフにしてもその時点ではsshdサービスは起動していてポートも開いてるから注意。
すぐにサービスを停止する場合は、/etc/rc.d/init.d/ディレクトリ内のサービス制御スクリプトを使います。
sshdを停止。
# /etc/rc.d/init.d/sshd stop
sshdを停止中: [ OK ]
(vineとかのレッドハット系なら # service sshd stop でもオッケー)
nmapでポートスキャン。ポートが閉じてることが確認できました。
# nmap -p 22 -sV -sT localhost
Starting Nmap 4.76 ( http://nmap.org ) at 2002-01-01 01:26 JST
Interesting ports on localhost (127.0.0.1):
PORT STATE SERVICE VERSION
22/tcp closed ssh
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.19 seconds
今度は起動。
# /etc/rc.d/init.d/sshd start
sshdを起動中: [ OK ]
(vineとかのレッドハット系なら # service sshd start でもオッケー)
再度nmapで確認。今度は開いてる。
# nmap -p 22 -sV -sT localhost
Starting Nmap 4.76 ( http://nmap.org ) at 2002-01-01 01:26 JST
Interesting ports on localhost (127.0.0.1):
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.22 seconds
(chkconfig --listでランレベルごとに見れるサービスはスタンドアロン型サービス。スーパーデーモン型は見れません。というか私のvine4.2はxinetdがないね・・・)
また、サービスを引数に指定することができます。
# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
sshdがオンになっていたのでオフに変更します。
# chkconfig sshd off
もう一度確認
# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:off 4:off 5:off 6:off
今度はオンにします。
# chkconfig sshd on
確認。
# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
レベルを指定して変更
# chkconfig --level 2345 sshd off
確認。
chkconfig --list sshd
sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
このオン、オフはあくまでPC起動時の設定ね。
chkconfigでsshdをオフにしてもその時点ではsshdサービスは起動していてポートも開いてるから注意。
すぐにサービスを停止する場合は、/etc/rc.d/init.d/ディレクトリ内のサービス制御スクリプトを使います。
sshdを停止。
# /etc/rc.d/init.d/sshd stop
sshdを停止中: [ OK ]
(vineとかのレッドハット系なら # service sshd stop でもオッケー)
nmapでポートスキャン。ポートが閉じてることが確認できました。
# nmap -p 22 -sV -sT localhost
Starting Nmap 4.76 ( http://nmap.org ) at 2002-01-01 01:26 JST
Interesting ports on localhost (127.0.0.1):
PORT STATE SERVICE VERSION
22/tcp closed ssh
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.19 seconds
今度は起動。
# /etc/rc.d/init.d/sshd start
sshdを起動中: [ OK ]
(vineとかのレッドハット系なら # service sshd start でもオッケー)
再度nmapで確認。今度は開いてる。
# nmap -p 22 -sV -sT localhost
Starting Nmap 4.76 ( http://nmap.org ) at 2002-01-01 01:26 JST
Interesting ports on localhost (127.0.0.1):
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.22 seconds