ちなみに最終目標はタイトル通りiPadからVPN接続ができることです。
まずはOpenVPNのパッケージをインストール。
$ apt-get install openvpn パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 以下の追加パッケージがインストールされます: libpkcs11-helper1 提案パッケージ: easy-rsa 以下のパッケージが新たにインストールされます: libpkcs11-helper1 openvpn アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。 462 kB のアーカイブを取得する必要があります。 この操作後に追加で 1,163 kB のディスク容量が消費されます。 続行しますか? [Y /n ] y |
$ apt-get install -- install -suggests easy-rsa パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 以下の追加パッケージがインストールされます: libccid opensc opensc-pkcs11 pcmciautils pcscd 以下のパッケージが新たにインストールされます: easy-rsa libccid opensc opensc-pkcs11 pcmciautils pcscd アップグレード: 0 個、新規インストール: 6 個、削除: 0 個、保留: 0 個。 1,108 kB のアーカイブを取得する必要があります。 この操作後に追加で 3,949 kB のディスク容量が消費されます。 続行しますか? [Y /n ] y |
- オレオレ認証局を作る(認証局と証明書)
- オレオレ認証局に認証されたサーバ証明書と秘密鍵を作成する
- 暗号化に使用するDiffie-Hellman用パラメータを作成する
- オレオレ認証局に認証されたクライアント証明書と公開鍵を作成する
- OpenVPNの設定・起動
1. オレオレ認証局を作る(認証局と証明書)
まずは認証局の情報を設定するために、初期設定されたディレクトリとファイルを作成する。
$ make -cadir /etc/openvpn/easy-rsa |
export EASY_RSA="/etc/openvpn/easy-rsa" #設定用のホームディレクトリ export KEY_COUNTRY="JP" export KEY_PROVINCE="OSAKA" export KEY_CITY="Minato-ku, Osaka" export KEY_ORG="High Mountain" export KEY_EMAIL="master@highmountain-lab.net" export KEY_OU="WEB Development Dept." |
$ source /etc/openvpn/easy-rsa/vars NOTE: If you run . /clean-all , I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys $ /etc/openvpn/easy-rsa/clean-all $ /etc/openvpn/easy-rsa/build-ca Generating a 2048 bit RSA private key .................................................................................+++ ....+++ writing new private key to 'ca.key' ----- 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. ----- Country Name (2 letter code) [JP]: State or Province Name (full name) [OSAKA]: Locality Name (eg, city) [Minato-ku, Osaka]: Organization Name (eg, company) [High Mountain]: Organizational Unit Name (eg, section) [WEB Development Dept.]: Common Name (eg, your name or your server's hostname ) [High Mountain CA]: Name [EasyRSA]: Email Address [master@highmountain-lab.net]: |
2. オレオレ認証局に認証されたサーバ証明書と秘密鍵を作成する
さっそくサーバ証明書と秘密鍵を作成しよう。
$ /etc/openvpn/easy-rsa/build-key-server LubuntuSakura Generating a 2048 bit RSA private key .........................................................+++ ................................+++ writing new private key to 'LubuntuSakura.key' ----- 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. ----- Country Name (2 letter code) [JP]: State or Province Name (full name) [OSAKA]: Locality Name (eg, city) [Minato-ku, Osaka]: Organization Name (eg, company) [High Mountain]: Organizational Unit Name (eg, section) [WEB Development Dept.]: Common Name (eg, your name or your server's hostname ) [LubuntuSakura]: Name [EasyRSA]: Email Address [master@highmountain-lab.net]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from /etc/openvpn/easy-rsa/openssl-1 .0.0.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE: 'JP' stateOrProvinceName :PRINTABLE: 'OSAKA' localityName :PRINTABLE: 'Minato-ku, Osaka' organizationName :PRINTABLE: 'High Mountain' organizationalUnitName:PRINTABLE: 'WEB Development Dept.' commonName :PRINTABLE: 'LubuntuSakura' name :PRINTABLE: 'EasyRSA' emailAddress :IA5STRING: 'master@highmountain-lab.net' Certificate is to be certified until May 15 18:40:00 2026 GMT (3650 days) Sign the certificate? [y /n ]:y 1 out of 1 certificate requests certified, commit? [y /n ]y Write out database with 1 new entries Data Base Updated |
3. 暗号化に使用するDiffie-Hellman用パラメータを作成する
/etc/openvpn/easy-rsa/build-dhを実行する。
$ /etc/openvpn/easy-rsa/build-dh Generating DH parameters, 2048 bit long safe prime, generator 2 This is going to take a long time .........................................................................+...........................................................................................................+.............................................................................................................................................+.............................+......................................+...............+................................................................................................................... |
4. オレオレ認証局に認証されたクライアント証明書と公開鍵を作成する
クイアント証明書と鍵を作成する。
# /etc/openvpn/easy-rsa/build-key LubuntuServerClient Generating a 2048 bit RSA private key ...........+++ ...................................................................................................+++ writing new private key to 'LubuntuServerClient.key' ----- 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. ----- Country Name (2 letter code) [JP]: State or Province Name (full name) [OSAKA]: Locality Name (eg, city) [Minato-ku, Osaka]: Organization Name (eg, company) [High Mountain]: Organizational Unit Name (eg, section) [WEB Development Dept.]: Common Name (eg, your name or your server's hostname ) [LubuntuServerClient]: Name [EasyRSA]: Email Address [master@highmountain-lab.net]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: Using configuration from /etc/openvpn/easy-rsa/openssl-1 .0.0.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE: 'JP' stateOrProvinceName :PRINTABLE: 'OSAKA' localityName :PRINTABLE: 'Minato-ku, Osaka' organizationName :PRINTABLE: 'High Mountain' organizationalUnitName:PRINTABLE: 'WEB Development Dept.' commonName :PRINTABLE: 'LubuntuServerClient' name :PRINTABLE: 'EasyRSA' emailAddress :IA5STRING: 'master@highmountain-lab.net' Certificate is to be certified until May 16 05:23:40 2026 GMT (3650 days) Sign the certificate? [y /n ]:y 1 out of 1 certificate requests certified, commit? [y /n ]y Write out database with 1 new entries Data Base Updated |
$ openvpn --genkey --secret /etc/openvpn/easy-rsa/keys/tls .key |
ca.crt LubuntuServerClient.crt LubuntuServerClient.key ta.key |
5. OpenVPNの設定・起動
OpenVPNサーバの設定をするのでサンプルのconfigファイルを/etc/openvpn配下に持って来て編集する。
$ cp /usr/share/doc/openvpn/examples/sample-config-files/server .conf.gz /etc/openvpn/ $ gunzip server.conf.gz |
port 1194 proto udp ca /etc/openvpn/easy-rsa/keys/ca.crt cert /etc/openvpn/easy-rsa/keys/LubuntuSakura.crt key /etc/openvpn/easy-rsa/keys/LubuntuSakura.key dh /etc/openvpn/easy-rsa/keys/dh2048.pem server 10.8.0.0 255.255.255.0 push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" client-to-client tls-auth /etc/openvpn/easy-rsa/keys/tls.key 0 user nobody group nogroup status /var/log/openvpn-status.log log-append /var/log/openvpn.log |
Activation: failed for connection '有線接続 1'とsyslogに出力され、うまく起動しなかったのでrebootしたらうまく起動された。
疲れた。iPad(iOS)から繋げるのは次回。