레이블이 centOS인 게시물을 표시합니다. 모든 게시물 표시
레이블이 centOS인 게시물을 표시합니다. 모든 게시물 표시

2017년 3월 9일 목요일

CentOSにSSH、Telnet、FTPをインストールする方法のまとめ。

■Telnetのインストール
Telnetのインストールはyumを使う。
[root@localhost ~]# yum install telnet-server
途中で以下のように聞かれるが、そのときは[y]を入力する
Is this ok [y/N]:
 
■Telnetサービスを自動で起動させる方法。
chkconfigを使う。
chkconfigはサービスの自動起動を制御するプログラムのこと。
オプション--listは現在のすべての設定を出力する。

[root@localhost ~]# chkconfig --list
NetworkManager  0:off 1:off 2:on 3:on 4:on 5:on 6:off
abrtd           0:off 1:off 2:off 3:on 4:off 5:on 6:off
acpid           0:off 1:off 2:on 3:on 4:on 5:on 6:off
atd             0:off 1:off 2:off 3:on 4:on 5:on 6:off
auditd          0:off 1:off 2:on 3:on 4:on 5:on 6:off
avahi-daemon    0:off 1:off 2:off 3:on 4:on 5:on 6:off
bluetooth       0:off 1:off 2:off 3:on 4:on 5:on 6:off
cgconfig        0:off 1:off 2:off 3:off 4:off 5:off 6:off
サービスを追加するための書式。

# chkconfig --add telnet
# chkconfig --list telnet
telnet          off
 
chkconfigの設定を切り替える書式
chkconfig --level <levels> <service> on|off|reset
上記の書式にしたがって、Telnetの設定をonにする。
[root@localhost ~]# chkconfig --level 35 telnet on
[root@localhost ~]# chkconfig --list telnet
telnet          on
 
ランレベル3,5でtelnetがonになった。
SSHのインストール
SSH(Secure SHell)はリモートコンピュータとの通信を暗号化や認証を用いて安全に行うためのプロトコルのこと。

openssh-serverをインストールする方法は以下の通り。

[root@localhost ~]# yum install openssh-server.x86_64 
パケットフィルタリングの設定が行われている場合、SSHの接続を許可するには、
外部からのSSHに関連する通信を許可する必要がある。

そのためにはiptablesを設定する必要がある。

# vi /etc/sysconfig/iptables
で、以下を追記する。(ついでにtelnetも追記)
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUt -m state --state NEW -m tcp -p tcp --dport 23 -j ACCEPT
 
公開鍵認証を行うためには、秘密鍵と公開鍵のペアである鍵セットを作成し、SSHサーバに公開鍵を登録する必要がある。

鍵セットの作成にはssh-keygenコマンドを使う必要があり、このコマンドはopensshパッケージとopenssh-clientsパッケージをインストールすることで使用可能になる。

鍵セットを作成する。

[sysmgr@localhost ~]$ ssh-keygen -t rsa
デフォルトだと、.sshディレクトリに鍵セットが作成される。
作成した公開鍵をauthrized_keysとして手元に持ってくる。

まず配布用公開鍵の作成。
[sysmgr@localhost .ssh]$ cat id_rsa.pub >> authorized_keys
[sysmgr@localhost .ssh]$ chmod 600 authorized_keys
 
まずはサーバ上で接続の確認
[sysmgr@localhost .ssh]$ ssh localhost
ローカルのホストのユーザ名と接続先のホストのユーザ名が異なる場合は、-lオプションを利用するか、@という形でユーザ名を指定する。

また、
SSHv2を使用した通信を指定する場合は-2、
SSHv1を使用した通信を指定する場合は-1
をオプションに指定する。

手元に公開鍵を持ってくる方法で、1番いいのは直接USBなどを指して物理媒体で移行する方法だ。

しかし、今回はFTPをインストールして、FTPで取得してみる。
まずはFTPのインストールから。

[root@localhost ~]# yum install vsftpd
vsftpdの自動起動をonにする。

[root@localhost ~]# chkconfig --list vsftpd
vsftpd          0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost ~]# chkconfig --level 35 vsftpd on
[root@localhost ~]# 
[root@localhost ~]# chkconfig --list vsftpd
vsftpd          0:off 1:off 2:off 3:on 4:off 5:on 6:off
 
また、vsftpdサービスを開始する。

[root@localhost ~]# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
 
SELinuxの設定で、匿名ユーザがファイルの読み書きができるようにする設定を行う。

[root@localhost log]# setsebool -P ftp_home_dir 1
[root@localhost log]# getsebool ftp_home_dir
ftp_home_dir --> on
 
これでFTPができるようになるので、手元に[authorized_keys]をダウンロードする。
あとはPuFFYを使ってsshで対象のサーバに接続すると、ssh通信ができた!!
参考にした本はこちら。

2017년 3월 4일 토요일

CentOS7のhttpd設定で詰まった点

初めてCentOS7を触ったのですが、いくつか詰まったところがあったのでまとめます。

serviceではなくsystemctlを使う

今までhttpdなどのサービスはserviceコマンドを使っていましたが、CentOS7からはsystemctlコマンドを使うことになります。
# sudo service httpd start の代わり
sudo systemctl start httpd.service

# sudo chkconfig httpd on の代わり
sudo systemctl enable httpd.service
末尾の.serivceは省略してもよいみたいです。

ファイアウォール設定を要確認

Firewall-cmdというファイアウォールが自動的に有効になっている場合があり、見落としがちです。
ポート80 (http) と 443 (https)を開けるには、下記のようにします。
firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

CentOSにApache HTTP Server(httpd)をインストールしてテストページを表示する

CentOSにApache HTTP Server(httpd)をインストールしてテストページを表示する

 

httpdのインストール

yumコマンドで httpd をインストールします。root で実行してください。

 

# yum -y install httpd
...
インストール:
  httpd.x86_64 0:2.2.15-39.el6.centos

依存性関連をインストールしました:
  apr.x86_64 0:1.3.9-5.el6_2     apr-util.x86_64 0:1.3.9-3.el6_0.1 
apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1  httpd-tools.x86_64 0:2.2.15-39.el6.centos
  mailcap.noarch 0:2.1.31-2.el6
...
# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Oct 16 2014 14:48:21
 
以下のようなディレクトリやファイルが作成されています。

/etc/httpd/
/etc/sysconfig/httpd
/etc/logrotate.d/httpd
/usr/lib64/httpd/
/var/www/
/var/run/httpd/
/var/log/httpd/
 
インストールが出来たら起動してみましょう。以下どちらのコマンドでも同じです。
# service httpd start
httpd を起動中: httpd: Could not reliably determine the server's fully 
qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]
---
# /etc/init.d/httpd start
httpd を起動中: httpd: Could not reliably determine the server's fully 
qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]
 
停止はstop、再起動はrestart、状態を確認するにはstatusを使用します。
起動した時にhttpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerNameというメッセージが表示されていますが、これは httpd.conf の ServerName を設定することで消えます。

# vi /etc/httpd/conf/httpd.conf
...
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work.  See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
ServerName www.example.com:80
...
# service httpd restart
httpd を停止中:                                            [  OK  ]
httpd を起動中:                                            [  OK  ]
 
起動後にブラウザで確認すると以下の画面が表示されます。
httpdをインストールしたマシンのブラウザならlocalhostやホスト名、
仮想マシンやサーバーにインストールした場合はIPアドレスを入力するだけでOKです。

ウェルカムページについて

先程ブラウザで確認した画面ですが、これは/etc/httpd/conf.d/welcome.confという設定ファイルによって、デフォルト状態でアクセスした時に表示されるようになっています。ファイルの中身は以下の通りです。

# cat /etc/httpd/conf.d/welcome.conf
<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /error/noindex.html
</LocationMatch>
 
 

httpdの自動起動

インストールした段階では自動起動がONになっていないため、再起動する度に手動で httpd を起動する必要があります。

# chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
 
自動起動をONにしておくことで起動する手間がいらなくなるのでしておきましょう。
# chkconfig httpd on
# chkconfig --list | grep httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off