AmzonLinux2023にOpenVPNをインストール
目次
1. 背景
Amaozn Linux 2023にOpenVPNを導入しようとしています。
ですが、思ったように動いてくれません。
これは作業中の記録です。
2. 実施したこと
2.1. openvpnにインストール
sudo yum -y install openvpn
バージョンの確認
rpm -q openvpn
openvpn-2.6.12-1.amzn2023.0.1.x86_64
2.2. easy-rsaのインストール
以下を参照して、最新を入れます。
https://github.com/OpenVPN/easy-rsa/releases
3.2.1が最新だったので、これをダウンロード。
wget https://github.com/OpenVPN/easy-rsa/releases/download/v3.2.1/EasyRSA-3.2.1.tgz
解凍。
tar -xvzf EasyRSA-3.2.1.tgz
解凍したフィアルを移動。
sudo mv EasyRSA-3.2.1 /usr/local/EasyRSA
移動先にcd。
cd /usr/local/EasyRSA/
2.3. 初期化
以下のコマンドで初期化。
./easyrsa init-pki
以下のメッセージが表示。「*(アスタリスク)」の部分を注意深く参照。
Notice
------
'init-pki' complete; you may now create a CA or requests.
Your newly created PKI dir is:
* /usr/local/EasyRSA/pki
Using Easy-RSA configuration:
* undefined
2.4. CAの作成
./easyrsa build-ca
パスフレーズを設定する。
Enter New CA Key Passphrase:
Passphrase must be at least 4 characters!
Enter New CA Key Passphrase:
Confirm New CA Key Passphrase:
..+.+.........+.....+...+..........+.....+......+.+...+..+....+.....+.......+..+..........+..+...+......+.+...........+....+......+........+.+.....+.....................+...+....+...+............+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+...+....+..................+..+.+..+...+.+...+........+.............+.........+..+....+.........+..+....+.....+.........+.......+...+..+.+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...............+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.+..............+....+..+.+............+..+....+.....+............+....+.....+................+..+.+......+...+........+...+..........+...........+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...+......+..+...+....+........+...+.+........+............+...+..........+..+...+............+.+...+.........+..+.+...+......+...+..+..................+.....................+.+......+.........+...........+....+...........+.......+..+...+..........+...........+....+.....+......+.........+.......+......+..+...+...+...............+.+......+........+......+......+....+...............+...+........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Common Nameの入力を促される。いったんは何も入れずにエンターキーのみ。Build-ca completed successfully.でうまくいったように見える。
-----
Common Name (eg: your user, host, or server name) [Easy-RSA CA]:
Notice
------
CA creation complete. Your new CA certificate is at:
* /usr/local/EasyRSA/pki/ca.crt
Create an OpenVPN TLS-AUTH|TLS-CRYPT-V1 key now: See 'help gen-tls'
Build-ca completed successfully.
---
2.5. DHパラメータ生成
以下のコマンド。
./easyrsa gen-dh
こんなメッセージが表示。「*(アスタリスク)」の部分にdh.pemのパスが表示されるので、メモる。
DH parameters appear to be ok.
Notice
------
DH parameters of size 2048 created at:
* /usr/local/EasyRSA/pki/dh.pem
2.6. サーバ用の秘密鍵と証明書の作成
サーバ用の秘密鍵と証明書の作成、署名をまとめて行います。nopassオプションで「パスフレーズ無し」で作成します。
./easyrsa build-server-full server nopass
以下のメッセージ。途中でyesの入力を求められるので、入力する。
.+..........+..............+...............+.+.....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*....+..+.+..+..........+......+.....+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*............+.....+...+.......+...+..+.......+..+.+..+..........+..................+...+..+.......+.....+................+.....+....+............+.....+......+.......+...+...+......+.....+..........+...+...........+....+...+..+......+......+.........+....+..+...+......+..........+.........+..+......+.......+..+...+.+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3. .+.....+......+..........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*....+...+.....+.+.....+.+...+...........+.........+.......+.....+.........+....+...+........+.+.........+..+...+....+...+.....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.............+.....+......+....+...+.....+.+...........+................+...+..+.........+.+.....+...+....+......+..+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
4. Notice
------
Private-Key and Public-Certificate-Request files created.
Your files are:
* req: /usr/local/EasyRSA/pki/reqs/server.req
* key: /usr/local/EasyRSA/pki/private/server.key
You are about to sign the following certificate:
Requested CN: 'server'
Requested type: 'server'
Valid for: '825' days
subject=
commonName = server
Type the word 'yes' to continue, or any other input to abort.
Confirm requested details:
Type the word 'yes' to continue, or any other input to abort.
Confirm requested details: yes
Using configuration from /usr/local/EasyRSA/pki/368f151b/temp.6.1
Enter pass phrase for /usr/local/EasyRSA/pki/private/ca.key:
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'server'
Certificate is to be certified until Apr 24 08:59:48 2027 GMT (825 days)
Write out database with 1 new entries
Data Base Updated
5. Notice
------
Inline file created:
* /usr/local/EasyRSA/pki/inline/private/server.inline
6. Notice
------
Certificate created at:
* /usr/local/EasyRSA/pki/issued/server.crt
[ec2-user@ip-10-0-0-9 EasyRSA]$
2.7. クライアント用秘密鍵/証明書の作成
サーバと同じようなメッセージなので、間違えないようにケアする。
./easyrsa build-client-full client1 nopass
以下のメッセージ。途中でyesの入力を求められるので、入力する。
.+.+..+....+......+.....+............+......+.......+...+......+....................+......+.........+...+............+...+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+...+......+......+.+...+.........+..+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+...+...........+.+.....+...............+.+..+...+.......+.....+.+.....+..........+..+...+.+........+......+.........+.......+..............+..........+.....+......+.+.....+.......+......+.........+...+..............+.+..+.............+...+....................+......+.+...+..+...+......+.+..+...+.......+......+......+...+.....+.+.........+..+.+........+......+.+.....+...+.........+.......+......+.....+.........+...+.......+...+..+....+..+.............+..+.........+.+...+.....+................+...+...+.....+...+.+......+........+......+......+......................+...+........+.+.....+..........+...............+......+.....+...+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7. .....+...........+.......+...+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...+....+.....+.........+.+...+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+.....+.............+............+.....+...+...+.......+...+...........+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-----
8. Notice
------
Private-Key and Public-Certificate-Request files created.
Your files are:
* req: /usr/local/EasyRSA/pki/reqs/client1.req
* key: /usr/local/EasyRSA/pki/private/client1.key
You are about to sign the following certificate:
Requested CN: 'client1'
Requested type: 'client'
Valid for: '825' days
subject=
commonName = client1
Type the word 'yes' to continue, or any other input to abort.
Confirm requested details: yes
Using configuration from /usr/local/EasyRSA/pki/f60211e9/temp.6.1
Enter pass phrase for /usr/local/EasyRSA/pki/private/ca.key:
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
commonName :ASN.1 12:'client1'
Certificate is to be certified until Apr 24 09:01:46 2027 GMT (825 days)
Write out database with 1 new entries
Data Base Updated
9. Notice
------
Inline file created:
* /usr/local/EasyRSA/pki/inline/private/client1.inline
10. Notice
------
Certificate created at:
* /usr/local/EasyRSA/pki/issued/client1.crt
2.8. 必要なファイルをコピー
以下でコピーする。sudoしないと権限ないと言われるので、sudoをつける。
sudo cp pki/ca.crt /etc/openvpn/
sudo cp pki/issued/server.crt /etc/openvpn/
sudo cp pki/private/server.key /etc/openvpn/
sudo cp pki/dh.pem /etc/openvpn/dh2048.pem
サーバのコンフィグファイル/etc/openvpn/server.confをひな形からコピーして作成する。
sudo cp /usr/share/doc/openvpn/sample/sample-config-files/server.conf /etc/openvpn/server.conf
3. 参考
以下の記事を参考にした。