14.4 OpenSSH
14.4.1 SSHの設定
普段遣いのWSL2環境のsshd設定
cat /etc/ssh/sshd_config
# $OpenBSD: sshd_config,v 1.101 2017/03/14 07:19:07 djm Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
Port 22
: 待受ポートListenAddress 0.0.0.0
,ListenAddress ::
: 待受アドレスHostKey /etc/ssh/ssh_host_rsa_key
: ホスト認証用の鍵-
SyslogFacility AUTH
: ログメッセージの種類を表す番号- https://tools.ietf.org/html/rfc3164
AUTH
は非推奨、AUTHPRIV
を使うべきらしい
LogLevel INFO
: ログレベルLoginGraceTime 2m
: ログインを試みることのできる最大時間(単位なしは秒数、2mは2分)PermitRootLogin prohibit-password
:no
推奨StrictModes yes
: ログイン前にパーミッション確認MaxAuthTries 6
: 接続ごとに何回ミスれるかRSAAuthentication
: SSH1パラメータ 公開鍵認証許可PubkeyAuthentication yes
: SSH2パラメータ 公開鍵認証許可AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
PasswordAuthentication: no
:no
推奨PermitEmptyPasswords no
:no
推奨UsePAM yes
: PAM使用 (ch12参照)-
X11Forwarding yes
: X11フォワーディング使用- ふだんこれでGUI作業してる
{Allow,Deny}{Users,Groups}
: ログイン許可/拒否するユーザー/グループSubsystem sftp /usr/lib/openssh/sftp-server
: 外部サブシステム(ファイル転送デーモン等)
14.4.2 ホスト認証とユーザー認証
ホスト認証
ユーザ認証に先立って接続先ホストの正当性を確認する
- これを行わず、DNSポイズニング等により気づかずに不正なホストにアクセスしてしまうとクレデンシャルを抜かれる
/etc/ssh/sshd_config
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
こいつら
-
SSH接続時に公開鍵をクライアントに送る
- クライアントの
~/.ssh/known_hosts
に永続化される
- クライアントの
- 次回以降はクライアントの
~/.ssh/known_hosts
の公開鍵とホストの/etc/ssh/
の秘密鍵を用いてホスト認証を行う
こんな感じ
head -1 ~/.ssh/known_hosts
github.com,192.30.255.113 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
こういうやつ
14.4.3 公開鍵認証
いつもの
- クライアントで鍵ペア作る
- クライアント公開鍵をサーバーの
~/.ssh/authorized_keys
(600)に追記
ssh-copy-id
コマンドを使うとサーバーへのクライアント公開鍵登録が楽ちん
ssh-keygen
鍵ペアを生成する…だけじゃない
鍵ペア生成
ssh-keygen -t ed25519 -f ~/.ssh/id_sample
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/wand/.ssh/id_sample.
Your public key has been saved in /home/wand/.ssh/id_sample.pub.
The key fingerprint is:
SHA256:zmuiudfSAw7bXap1j5rHnfj0pWMUWSkM1zsWxt1jKPc wand@lpic2-study-1
The key's randomart image is:
+--[ED25519 256]--+
| .o.+ +|
| ..= O+|
| o =o+|
| oE |
| S ...|
| . .o . . |
| = =++.o.o .|
| ..*.B+++o.oo |
| ++.=++..o.o. |
+----[SHA256]-----+
-t
: 暗号化方式
rsa1
: SSH v1 RSAdsa
: SSH v2 DSArsa
: SSH v2 RSAecdsa
: SSH v2 ECDSAed25519
: SSH v2 ED25519
コマンドラインでパスフレーズ変更
-p
: 既存の秘密鍵のパスフレーズ変更-P
: 古いパスフレーズ-N
: 新しいパスフレーズ
ssh-keygen -p -P hoge -N piyo -f ~/.ssh/id_sample
Key has comment 'wand@lpic2-study-1'
Your identification has been saved with the new passphrase.
既存の鍵のフィンガープリント表示
ssh-keygen -l -f ~/.ssh/id_sample
256 SHA256:zmuiudfSAw7bXap1j5rHnfj0pWMUWSkM1zsWxt1jKPc wand@lpic2-study-1 (ED25519)
指定のホストの鍵をknown_hosts
から削除
ssh-keygen -R ホスト
14.4.4 ssh-agent
秘密鍵を使用するたびにパスフレーズ入力は面倒
かといってパスフレーズ設定しないのは危ない
ssh-agent
: クライアントのメモリ上で秘密鍵を保持する
ssh-agent
の子プロセスとしてシェル起動
ssh-agent bash
ssh-add
で秘密鍵選択・パスフレーズ入力して入力- 以降、その鍵はパスフレーズ入力不要
column: パスフレーズなしの鍵の利用
authorized_keys
で鍵ごとにコマンド、ネットワーク、機能等を制限できる
command="コマンド" ssh-rsa AAAAB...
from="ネットワーク" ssh-rsa AAAAB...
no-X11-forwarding ssh-rsa AAAAB...
- 指定のコマンドを実行して切断、終了
- 接続元ネットワーク制限
- X11 Forwarding使用不可
14.4.5 SSHポート転送
踏み台でよく使うやつ
ローカル13306
番をbastion
ホスト経由でdb_host
ホストの3306
番に繋ぐ
ssh -L 13306:db_host:3306 ssh_user@bastion
別のターミナルで
mysql -h 127.0.0.1 -P 13306 -u db_user -p
14.4.6 SSHサーバのセキュリティ
SSHバージョン1の禁止
v1は安全性が確保できない
Protocol 2
パスワード認証の禁止
クライアントの公開鍵をサーバの~/.ssh/authorized_keys
に登録できたらもういらない
PasswordAuthentication no
rootログインの禁止
PermitRootLogin no
ログインユーザーの制限
AllowUsers
/DenyUsers
/AllowGroups
/DenyGroups
によるアクセス制限
Allowを設定すると、マッチしないものは拒否される
接続元の制限
ldd $(which sshd) | grep libwrap
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007f5564405000)
libwrap
共有ライブラリに依存している = TCP Wrapperを利用している
つまり、 /etc/hosts.allow
, /etc/hosts.deny
によるアクセス制御が可能
/etc/hosts.allow
sshd: 172.16.
/etc/hosts.deny
sshd: ALL
14.5 セキュリティ業務
14.5.1 セキュリティツール
Snort
ルールベースのパケットスニッファ
パケットキャプチャライブラリlibpcap
必要
Tripwire
改竄検知システム
ファイルシステムの状況のスナップショットを記録しておき比較する
チェックできる内容
-
iノードの情報
- パーミッション、リンク数、有ユーザー/グループ等
-
スーパーブロックの情報
- iノード番号等
- ハッシュ値
OpenVAS
OpenVAS: Open Vulnerability Assessment System
ネットワーク経由で脆弱性チェックできる
Fail2ban
yum provides fail2ban
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ty1.mirror.newmediaexpress.com
* epel: d2lzkl7pfhq30w.cloudfront.net
* extras: ty1.mirror.newmediaexpress.com
* updates: ty1.mirror.newmediaexpress.com
google-cloud-sdk 974/974
fail2ban-0.11.1-10.el7.noarch : Daemon to ban hosts that cause multiple authentication errors
Repo : epel
fail2ban
パッケージで入る
- firewalldやsshdと連携し、syslogログを監視
- 設定されたアクションを検知してアクセス遮断
14.5.2 開いているポートの表示
よそに行うのは攻撃なのでやめようね
nmap
sudo yum -y install nmap
sudo nmap localhost
Starting Nmap 6.40 ( http://nmap.org ) at 2021-01-07 16:22 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000019s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
111/tcp open rpcbind
Nmap done: 1 IP address (1 host up) scanned in 1.62 seconds
Xmasツリースキャン: FIN,URG,PSHフラグ有効にしたTCPセグメントを送りつけて反応をみる
- 複数のフラグが立てられるさまをオーナメントに見立てているとか
sudo nmap -sX localhost
けっこう時間かかる
Starting Nmap 6.40 ( http://nmap.org ) at 2021-01-07 16:24 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000098s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open|filtered ssh
25/tcp open|filtered smtp
111/tcp open|filtered rpcbind
Nmap done: 1 IP address (1 host up) scanned in 96.66 seconds
【補】nc -z <host> <portspec>
も使えるがCentOSだと閉じているポートに当たった瞬間exit 1してしまう
netstat
sudo netstat -atun
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:49145 0.0.0.0:* LISTEN
tcp 0 0 10.146.0.4:22 xx.xx.xx.xx:59862 ESTABLISHED
tcp 0 0 10.146.0.4:44854 169.254.169.254:80 ESTABLISHED
tcp 0 0 10.146.0.4:22 xx.xx.xx.xx:59832 ESTABLISHED
tcp 0 0 10.146.0.4:44862 169.254.169.254:80 ESTABLISHED
tcp 0 0 10.146.0.4:60018 172.217.26.42:443 ESTABLISHED
tcp 0 0 10.146.0.4:33622 172.217.161.74:443 ESTABLISHED
tcp6 0 0 :::39753 :::* LISTEN
tcp6 0 0 :::111 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
udp 0 0 0.0.0.0:623 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 127.0.0.1:659 0.0.0.0:*
udp 0 0 127.0.0.1:323 0.0.0.0:*
udp 0 0 0.0.0.0:33285 0.0.0.0:*
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp6 0 0 :::623 :::*
udp6 0 0 :::111 :::*
udp6 0 0 ::1:323 :::*
udp6 0 0 :::46532 :::*
ss
ss -atun
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 *:623 *:*
udp UNCONN 0 0 *:111 *:*
udp UNCONN 0 0 127.0.0.1:659 *:*
udp UNCONN 0 0 127.0.0.1:323 *:*
udp UNCONN 0 0 *:33285 *:*
udp UNCONN 0 0 *:68 *:*
udp UNCONN 0 0 [::]:623 [::]:*
udp UNCONN 0 0 [::]:111 [::]:*
udp UNCONN 0 0 [::1]:323 [::]:*
udp UNCONN 0 0 [::]:46532 [::]:*
tcp LISTEN 0 128 *:111 *:*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 127.0.0.1:25 *:*
tcp LISTEN 0 128 *:49145 *:*
tcp ESTAB 0 1148 10.146.0.4:22 xx.xx.xx.xx:59862
tcp ESTAB 0 0 10.146.0.4:44854 169.254.169.254:80
tcp ESTAB 0 0 10.146.0.4:22 xx.xx.xx.xx:59832
tcp ESTAB 0 0 10.146.0.4:44862 169.254.169.254:80
tcp ESTAB 0 0 10.146.0.4:60018 172.217.26.42:443
tcp ESTAB 0 0 10.146.0.4:33622 172.217.161.74:443
tcp LISTEN 0 128 [::]:39753 [::]:*
tcp LISTEN 0 128 [::]:111 [::]:*
tcp LISTEN 0 128 [::]:22 [::]:*
tcp LISTEN 0 100 [::1]:25 [::]:*
lsof
sudo lsof -i -n
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 460 rpc 6u IPv4 14770 0t0 UDP *:sunrpc
rpcbind 460 rpc 7u IPv4 14820 0t0 UDP *:asf-rmcp
rpcbind 460 rpc 8u IPv4 14821 0t0 TCP *:sunrpc (LISTEN)
rpcbind 460 rpc 9u IPv6 14822 0t0 UDP *:sunrpc
rpcbind 460 rpc 10u IPv6 14823 0t0 UDP *:asf-rmcp
rpcbind 460 rpc 11u IPv6 14824 0t0 TCP *:sunrpc (LISTEN)
chronyd 475 chrony 5u IPv4 15105 0t0 UDP 127.0.0.1:323
chronyd 475 chrony 6u IPv6 15106 0t0 UDP [::1]:323
dhclient 645 root 6u IPv4 16617 0t0 UDP *:bootpc
google_os 879 root 3u IPv4 18661 0t0 TCP 10.146.0.4:44854->169.254.169.254:http (ESTABLISHED)
google_os 879 root 6u IPv4 52750 0t0 TCP 10.146.0.4:48040->216.58.197.170:https (ESTABLISHED)
rpc.statd 888 rpcuser 7u IPv4 18461 0t0 UDP *:33285
rpc.statd 888 rpcuser 8u IPv4 18468 0t0 TCP *:49145 (LISTEN)
rpc.statd 888 rpcuser 9u IPv6 18472 0t0 UDP *:46532
rpc.statd 888 rpcuser 10u IPv6 18476 0t0 TCP *:39753 (LISTEN)
rpc.statd 888 rpcuser 25u IPv4 17227 0t0 UDP 127.0.0.1:659
google_gu 902 root 3u IPv4 18675 0t0 TCP 10.146.0.4:44862->169.254.169.254:http (ESTABLISHED)
google_gu 902 root 6u IPv4 52066 0t0 TCP 10.146.0.4:37878->216.58.220.106:https (ESTABLISHED)
master 1034 root 13u IPv4 18244 0t0 TCP 127.0.0.1:smtp (LISTEN)
master 1034 root 14u IPv6 18245 0t0 TCP [::1]:smtp (LISTEN)
sshd 1241 root 3u IPv4 19520 0t0 TCP *:ssh (LISTEN)
sshd 1241 root 4u IPv6 19522 0t0 TCP *:ssh (LISTEN)
sshd 2702 root 3u IPv4 40897 0t0 TCP 10.146.0.4:ssh->xx.xx.xx.xx:59832 (ESTABLISHED)
sshd 2705 wand 3u IPv4 40897 0t0 TCP 10.146.0.4:ssh->xx.xx.xx.xx:59832 (ESTABLISHED)
sshd 3341 root 3u IPv4 48914 0t0 TCP 10.146.0.4:ssh->xx.xx.xx.xx:59862 (ESTABLISHED)
sshd 3344 wand 3u IPv4 48914 0t0 TCP 10.146.0.4:ssh->xx.xx.xx.xx:59862 (ESTABLISHED)
特定のポートのみも可
sudo lsof -i:22 -n
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1241 root 3u IPv4 19520 0t0 TCP *:ssh (LISTEN)
sshd 1241 root 4u IPv6 19522 0t0 TCP *:ssh (LISTEN)
sshd 2702 root 3u IPv4 40897 0t0 TCP 10.146.0.4:ssh->xx.xx.xx.xx:59832 (ESTABLISHED)
sshd 2705 wand 3u IPv4 40897 0t0 TCP 10.146.0.4:ssh->xx.xx.xx.xx:59832 (ESTABLISHED)
sshd 3341 root 3u IPv4 48914 0t0 TCP 10.146.0.4:ssh->xx.xx.xx.xx:59862 (ESTABLISHED)
sshd 3344 wand 3u IPv4 48914 0t0 TCP 10.146.0.4:ssh->xx.xx.xx.xx:59862 (ESTABLISHED)
fuser
これは特定ポートのみ
sudo fuser -v -n tcp 22
USER PID ACCESS COMMAND
22/tcp: root 1241 F.... sshd
root 2702 F.... sshd
wand 2705 F.... sshd
root 3341 F.... sshd
wand 3344 F.... sshd
14.5.3 TCP Wrapper
TCP/IP通信をlibwrap共有ライブラリにより集中管理する仕組み
/etc/hosts.allow
, /etc/hosts.deny
でアクセス制御
- allowで許可されなかったものはdenyを見に行く
- denyを見に行って拒否されなかったものは許可
書式: daemon_list : client_list : option : option ...
例:
ALL: .friendly.domain: ALLOW
ALL: ALL: DENY
ALL: .bad.domain: DENY
ALL: ALL: ALLOW
sshd: LOCAL
spawn
: 子プロセスで特定のコマンド実行
ALL:ALL:spawn (/some/where/safe_finger -l @%h | /usr/ucb/mail root) &
twist
: source
とか.
とか相当
in.ftpd : ... : twist /bin/echo 421 Some bounce message
in.telnetd : ... : twist PATH=/some/other; exec in.telnetd
14.5.4 セキュリティ情報源
すみやかな対応のために情報収集が必要不可欠
-
CERT/CC
- 事故情報収集、技術支援情報発信
- 日本ではJPCERT
-
BUGTRAQ
- バグ情報公開メーリングリスト
-
CIAC: Computer Incident Advisory Capability
- さまざまなセキュリティインシデントの報告や通知
-
IPA
- おなじみ
14.5.5 セキュリティ侵害への対処
ls
は/usr/bin/
にある実行ファイルなので改ざんされうる
- 不正なファイルだけ表示しないよう、など
type ls
ls is /usr/bin/ls
シェルビルトインのecho
で代替できる
type echo
echo is a shell builtin
echo *
Maildir httpd ldap lo public_html tmp
rpm
で改竄検出
rpm -Va
-V
,--verify
-a
,--all
...
..?...... c /etc/sysconfig/sshd
S.5....T. c /etc/sysconfig/authconfig
S.5....T. c /etc/postfix/main.cf
S.5....T. c /etc/chrony.conf
missing /etc/dhcp/dhclient.d/chrony.sh (Permission denied)
...
.M....... g /var/lock/iscsi
...
....L.... c /etc/pam.d/fingerprint-auth
管理者権限がないとじゃないと?
とかmissing
とか結構出る
RPM検証記号の意味
S
: size相違M
: アクセス権かファイルタイプ相違5
: MD5チェックサム相違L
: symlink相違U
: 所有者相違G
: グループ相違T
: 更新時刻相違D
: デバイスファイル相違?
: 不明c
: config fileの意
14.6 OpenVPN
14.6.1 OpenVPNの概要
sudo yum -y install openvpn
ルーティング接続
- L3でVPN
- 仮想トンネルネットワーク経由
- クライアントとサーバで別々のセグメント
- 大規模アクセス制御向き
ブリッジ接続
- L2でVPN
- 仮想インタフェース経由
-
接続先と同じセグメント -> ブロードキャストが届く
- SambaやWindowsサーバが使える
- 小規模ネットワーク・個人向け
14.6.2 必要なファイルの作成
インストール
sudo yum -y install openvpn
sudo ls -lR /etc/openvpn/
/etc/openvpn/:
total 0
drwxr-x---. 2 root openvpn 6 Dec 9 16:57 client
drwxr-x---. 2 root openvpn 6 Dec 9 16:57 server
/etc/openvpn/client:
total 0
/etc/openvpn/server:
total 0
空なんすけど
https://github.com/OpenVPN/easy-rsa/releases/tag/v2.2.0 からファイル
sudo curl -L https://github.com/OpenVPN/easy-rsa/archive/v2.2.0.tar.gz -o v2.2.0.tar.gz
sudo tar xvzf v2.2.0.tar.gz
cd /etc/openvpn/easy-rsa-2.2.0/easy-rsa/2.0
ls
build-ca build-key-pass build-req-pass openssl-0.9.6.cnf revoke-full
build-dh build-key-pkcs12 clean-all openssl-0.9.8.cnf sign-req
build-inter build-key-server inherit-inter openssl-1.0.0.cnf vars
build-key build-req list-crl pkitool whichopensslcnf
パラメータの準備
サーバ証明書やCA証明書の作成用パラメータ用意
cat vars
# easy-rsa parameter settings
# NOTE: If you installed from an RPM,
# don't edit this file in place in
# /usr/share/openvpn/easy-rsa --
# instead, you should copy the whole
# easy-rsa directory to another location
# (such as /etc/openvpn) so that your
# edits will not be wiped out by a future
# OpenVPN package upgrade.
# This variable should point to
# the top level of the easy-rsa
# tree.
export EASY_RSA="`pwd`"
#
# This variable should point to
# the requested executables
#
export OPENSSL="openssl"
export PKCS11TOOL="pkcs11-tool"
export GREP="grep"
# This variable should point to
# the openssl.cnf file included
# with easy-rsa.
export KEY_CONFIG=`$EASY_RSA/whichopensslcnf $EASY_RSA`
# Edit this variable to point to
# your soon-to-be-created key
# directory.
#
# WARNING: clean-all will do
# a rm -rf on this directory
# so make sure you define
# it correctly!
export KEY_DIR="$EASY_RSA/keys"
# Issue rm -rf warning
echo NOTE: If you run ./clean-all, I will be doing a rm -rf on $KEY_DIR
# PKCS11 fixes
export PKCS11_MODULE_PATH="dummy"
export PKCS11_PIN="dummy"
# Increase this to 2048 if you
# are paranoid. This will slow
# down TLS negotiation performance
# as well as the one-time DH parms
# generation process.
export KEY_SIZE=1024
# In how many days should the root CA key expire?
export CA_EXPIRE=3650
# In how many days should certificates expire?
export KEY_EXPIRE=3650
# These are the default values for fields
# which will be placed in the certificate.
# Don't leave any of these fields blank.
export KEY_COUNTRY="US"
export KEY_PROVINCE="CA"
export KEY_CITY="SanFrancisco"
export KEY_ORG="Fort-Funston"
export KEY_EMAIL="me@myhost.mydomain"
export KEY_EMAIL=mail@host.domain
export KEY_CN=changeme
export KEY_NAME=changeme
export KEY_OU=changeme
export PKCS11_MODULE_PATH=changeme
export PKCS11_PIN=1234
このへん変える
export KEY_COUNTRY="JP"
export KEY_PROVINCE="TOKYO"
export KEY_CITY="Shinjuku"
export KEY_ORG="LPIC"
export KEY_EMAIL="me@myhost.mydomain"
export KEY_EMAIL=mail@host.domain
export KEY_CN=changeme
export KEY_NAME=changeme
export KEY_OU=changeme
export PKCS11_MODULE_PATH=changeme
export PKCS11_PIN=1234
変数反映
sudo -i
# cd /etc/openvpn/easy-rsa-2.2.0/easy-rsa/2.0
# . vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa-2.2.0/easy-rsa/2.0/keys
おそうじ
# ./clean-all
Please source the vars script first (i.e. "source ./vars")
Make sure you have edited it to reflect your configuration.
CA証明書、CA秘密鍵の作成
# ./build-ca
Generating a 1024 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) [TOKYO]:
Locality Name (eg, city) [Shinjuku]:
Organization Name (eg, company) [LPIC]:
Organizational Unit Name (eg, section) [changeme]:
Common Name (eg, your name or your server's hostname) [changeme]:
Name [changeme]:
Email Address [mail@host.domain]:
CA証明書ファイル ca.crt
とCA秘密鍵ファイル ca.key
ができる
ls keys
ca.crt ca.key index.txt serial
-
サーバの
/etc/openvpn/keys/
に配置する- CA証明書はクライアントにも
サーバ証明書、サーバ秘密鍵の作成
# ./build-key-server server
Generating a 1024 bit RSA private key
..............................++++++
........................++++++
writing new private key to 'server.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) [TOKYO]:
Locality Name (eg, city) [Shinjuku]:
Organization Name (eg, company) [LPIC]:
Organizational Unit Name (eg, section) [changeme]:
Common Name (eg, your name or your server's hostname) [server]:
Name [changeme]:
Email Address [mail@host.domain]:
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-2.2.0/easy-rsa/2.0/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:'TOKYO'
localityName :PRINTABLE:'Shinjuku'
organizationName :PRINTABLE:'LPIC'
organizationalUnitName:PRINTABLE:'changeme'
commonName :PRINTABLE:'server'
name :PRINTABLE:'changeme'
emailAddress :IA5STRING:'mail@host.domain'
Certificate is to be certified until Jan 6 17:17:53 2031 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
サーバ名 server
に対応する サーバ証明書 server.crt
、サーバ秘密鍵 server.key
ができる
ls keys
01.pem ca.key index.txt.attr serial server.crt server.key
ca.crt index.txt index.txt.old serial.old server.csr
これも /etc/openvpn/keys/
へ
DHパラメータの作成
DH: Diffie-Hellman key exchange
- 頭頂の可能性のある通信路を経由して共通鍵暗号の秘密鍵を共有する
そのためのバラメータを生成する
# ./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
......................+............... ...
ls keys
01.pem ca.key index.txt index.txt.old serial.old server.csr
ca.crt dh1024.pem index.txt.attr serial server.crt server.key
dh1024.pem
ができる
これも/etc/openvpn/keys/
へ
クライアント証明書、クライアント秘密鍵の作成
# ./build-key client
Generating a 1024 bit RSA private key
..........++++++
.....++++++
writing new private key to 'client.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) [TOKYO]:
Locality Name (eg, city) [Shinjuku]:
Organization Name (eg, company) [LPIC]:
Organizational Unit Name (eg, section) [changeme]:
Common Name (eg, your name or your server's hostname) [client]:
Name [changeme]:
Email Address [mail@host.domain]:
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-2.2.0/easy-rsa/2.0/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:'TOKYO'
localityName :PRINTABLE:'Shinjuku'
organizationName :PRINTABLE:'LPIC'
organizationalUnitName:PRINTABLE:'changeme'
commonName :PRINTABLE:'client'
name :PRINTABLE:'changeme'
emailAddress :IA5STRING:'mail@host.domain'
Certificate is to be certified until Jan 6 17:25:15 2031 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
クライアントのホスト名client
に対して
client.key
: クライアント秘密鍵client.crt
: クライアント証明書要求client.csr
: クライアント証明書
ができる
クライアントの /etc/openvpn/keys/
に配置する
起動スクリプトの設定
ls /usr/share/doc/openvpn-2.4.10/sample/sample-scripts
auth-pam.pl bridge-start bridge-stop ucn.pl verify-cn
ブリッジ接続のサンプルスクリプトが置いてある
cat /usr/share/doc/openvpn-2.4.10/sample/sample-scripts/bridge-start
#!/bin/sh
#################################
# Set up Ethernet bridge on Linux
# Requires: bridge-utils
#################################
# Define Bridge Interface
br="br0"
# Define list of TAP interfaces to be bridged,
# for example tap="tap0 tap1 tap2".
tap="tap0"
# Define physical ethernet interface to be bridged
# with TAP interface(s) above.
eth="eth0"
eth_ip="192.168.8.4"
eth_netmask="255.255.255.0"
eth_broadcast="192.168.8.255"
for t in $tap; do
openvpn --mktun --dev $t
done
brctl addbr $br
brctl addif $br $eth
for t in $tap; do
brctl addif $br $t
done
for t in $tap; do
ifconfig $t 0.0.0.0 promisc up
done
ifconfig $eth 0.0.0.0 promisc up
ifconfig $br $eth_ip netmask $eth_netmask broadcast $eth_broadcast
cat /usr/share/doc/openvpn-2.4.10/sample/sample-scripts/bridge-stop
#!/bin/sh
####################################
# Tear Down Ethernet bridge on Linux
####################################
# Define Bridge Interface
br="br0"
# Define list of TAP interfaces to be bridged together
tap="tap0"
ifconfig $br down
brctl delbr $br
for t in $tap; do
openvpn --rmtun --dev $t
done
これらを /etc/openvpn/
に置いておく
14.6.3 OpenVPNサーバの設定
/usr/share/doc/openvpn-2.x.y/
に設定サンプルがある
ls /usr/share/doc/openvpn-2.4.10/sample/
sample-config-files sample-scripts sample-windows
ls /usr/share/doc/openvpn-2.4.10/sample/sample-config-files/
README office.up static-home.conf
client.conf openvpn-shutdown.sh static-office.conf
firewall.sh openvpn-startup.sh tls-home.conf
home.up roadwarrior-client.conf tls-office.conf
loopback-client roadwarrior-server.conf xinetd-client-config
loopback-server server.conf xinetd-server-config
cat /usr/share/doc/openvpn-2.4.10/sample/sample-config-files/server.conf
#################################################
# Sample OpenVPN 2.0 config file for #
# multi-client server. #
# #
# This file is for the server side #
# of a many-clients <-> one-server #
# OpenVPN configuration. #
# #
# OpenVPN also supports #
# single-machine <-> single-machine #
# configurations (See the Examples page #
# on the web site for more info). #
# #
# This config should work on Windows #
# or Linux/BSD systems. Remember on #
# Windows to quote pathnames and use #
# double backslashes, e.g.: #
# "C:\\Program Files\\OpenVPN\\config\\foo.key" #
# #
# Comments are preceded with '#' or ';' #
#################################################
# Which local IP address should OpenVPN
# listen on? (optional)
;local a.b.c.d
# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one. You will need to
# open up this port on your firewall.
port 1194
# TCP or UDP server?
;proto tcp
proto udp
# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel if you
# have more than one. On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap
# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key). Each client
# and the server must have their own cert and
# key file. The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys. Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca ca.crt
cert server.crt
key server.key # This file should be kept secret
# Diffie hellman parameters.
# Generate your own with:
# openssl dhparam -out dh2048.pem 2048
dh dh2048.pem
# Network topology
# Should be subnet (addressing via IP)
# unless Windows clients v2.0.9 and lower have to
# be supported (then net30, i.e. a /30 per client)
# Defaults to net30 (not recommended)
;topology subnet
# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 10.8.0.0 255.255.255.0
# Maintain a record of client <-> virtual IP address
# associations in this file. If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
ifconfig-pool-persist ipp.txt
# Configure server mode for ethernet bridging.
# You must first use your OS's bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface. Then you must manually set the
# IP/netmask on the bridge interface, here we
# assume 10.8.0.4/255.255.255.0. Finally we
# must set aside an IP range in this subnet
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients. Leave this line commented
# out unless you are ethernet bridging.
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
# Configure server mode for ethernet bridging
# using a DHCP-proxy, where clients talk
# to the OpenVPN server-side DHCP server
# to receive their IP address allocation
# and DNS server addresses. You must first use
# your OS's bridging capability to bridge the TAP
# interface with the ethernet NIC interface.
# Note: this mode only works on clients (such as
# Windows), where the client-side TAP adapter is
# bound to a DHCP client.
;server-bridge
# Push routes to the client to allow it
# to reach other private subnets behind
# the server. Remember that these
# private subnets will also need
# to know to route the OpenVPN client
# address pool (10.8.0.0/255.255.255.0)
# back to the OpenVPN server.
;push "route 192.168.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"
# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).
# EXAMPLE: Suppose the client
# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# First, uncomment out these lines:
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
# Then create a file ccd/Thelonious with this line:
# iroute 192.168.40.128 255.255.255.248
# This will allow Thelonious' private subnet to
# access the VPN. This example will only work
# if you are routing, not bridging, i.e. you are
# using "dev tun" and "server" directives.
# EXAMPLE: Suppose you want to give
# Thelonious a fixed VPN IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
# ifconfig-push 10.9.0.1 10.9.0.2
# Suppose that you want to enable different
# firewall access policies for different groups
# of clients. There are two methods:
# (1) Run multiple OpenVPN daemons, one for each
# group, and firewall the TUN/TAP interface
# for each group/daemon appropriately.
# (2) (Advanced) Create a script to dynamically
# modify the firewall in response to access
# from different clients. See man
# page for more info on learn-address script.
;learn-address ./script
# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
;push "redirect-gateway def1 bypass-dhcp"
# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses. CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.com.
;push "dhcp-option DNS 208.67.222.222"
;push "dhcp-option DNS 208.67.220.220"
# Uncomment this directive to allow different
# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server's TUN/TAP interface.
;client-to-client
# Uncomment this directive if multiple clients
# might connect with the same certificate/key
# files or common names. This is recommended
# only for testing purposes. For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
;duplicate-cn
# The keepalive directive causes ping-like
# messages to be sent back and forth over
# the link so that each side knows when
# the other side has gone down.
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 10 120
# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
# openvpn --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.
# The second parameter should be '0'
# on the server and '1' on the clients.
tls-auth ta.key 0 # This file is secret
# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
# Note that v2.4 client/server will automatically
# negotiate AES-256-GCM in TLS mode.
# See also the ncp-cipher option in the manpage
cipher AES-256-CBC
# Enable compression on the VPN link and push the
# option to the client (v2.4+ only, for earlier
# versions see below)
;compress lz4-v2
;push "compress lz4-v2"
# For compression compatible with older clients use comp-lzo
# If you enable it here, you must also
# enable it in the client config file.
;comp-lzo
# The maximum number of concurrently connected
# clients we want to allow.
;max-clients 100
# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
;user nobody
;group nobody
# The persist options will try to avoid
# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun
# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
status openvpn-status.log
# By default, log messages will go to the syslog (or
# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,
# while "log-append" will append to it. Use one
# or the other (but not both).
;log openvpn.log
;log-append openvpn.log
# Set the appropriate level of log
# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 3
# Silence repeating messages. At most 20
# sequential messages of the same message
# category will be output to the log.
;mute 20
# Notify the client that when the server restarts so it
# can automatically reconnect.
抜粋
# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one. You will need to
# open up this port on your firewall.
port 1194
# TCP or UDP server?
;proto tcp
proto udp
UDP/1194 を使用するのでfirewallに穴あけしておく必要がある
# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
tap
: L2 (ブリッジ接続)tun
: L3 (ルーティング接続)
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca ca.crt
cert server.crt
key server.key # This file should be kept secret
# Diffie hellman parameters.
# Generate your own with:
# openssl dhparam -out dh2048.pem 2048
dh dh2048.pem
- さっき一所懸命作った鍵や証明書ファイル群
-
しかるべき値に直す
ca keys/ca.crt
cert keys/server.crt
key server.key
dh keys/dh1024.pem
# Enable compression on the VPN link and push the
# option to the client (v2.4+ only, for earlier
# versions see below)
;compress lz4-v2
;push "compress lz4-v2"
push
: OpenVPNクライアントに渡す情報
# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
;user nobody
;group nobody
user
/group
: OpenVPNデーモンの実行ユーザ/グループ
# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
status openvpn-status.log
status
: 接続中クライアントリストファイル
/var/log/
配下とかに変えよう
# By default, log messages will go to the syslog (or
# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,
# while "log-append" will append to it. Use one
# or the other (but not both).
;log openvpn.log
;log-append openvpn.log
log
: ログ出力先ファイル
- 指定なき場合Syslog
カーネルパラメータ net.ipv4.ip_forward
を有効にしてopenvpn-bridge
サービス起動
14.6.4 OpenVPNクライアントの設定
cat /usr/share/doc/openvpn-2.4.10/sample/sample-config-files/client.conf
##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #
# #
# This configuration can be used by multiple #
# clients, however each client should have #
# its own cert and key files. #
# #
# On Windows, you might want to rename this #
# file so it has a .ovpn extension #
##############################################
# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client
# Use the same setting as you are using on
# the server.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one. On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap
# Are we connecting to a TCP or
# UDP server? Use the same setting as
# on the server.
;proto tcp
proto udp
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote my-server-1 1194
;remote my-server-2 1194
# Choose a random host from the remote
# list for load-balancing. Otherwise
# try hosts in the order specified.
;remote-random
# Keep trying indefinitely to resolve the
# host name of the OpenVPN server. Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite
# Most clients don't need to bind to
# a specific local port number.
nobind
# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nobody
# Try to preserve some state across restarts.
persist-key
persist-tun
# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here. See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]
# Wireless networks often produce a lot
# of duplicate packets. Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings
# SSL/TLS parms.
# See the server config file for more
# description. It's best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
ca ca.crt
cert client.crt
key client.key
# Verify server certificate by checking that the
# certicate has the correct key usage set.
# This is an important precaution to protect against
# a potential attack discussed here:
# http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the keyUsage set to
# digitalSignature, keyEncipherment
# and the extendedKeyUsage to
# serverAuth
# EasyRSA can do this for you.
remote-cert-tls server
# If a tls-auth key is used on the server
# then every client must also have the key.
tls-auth ta.key 1
# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
# Note that v2.4 client/server will automatically
# negotiate AES-256-GCM in TLS mode.
# See also the ncp-cipher option in the manpage
cipher AES-256-CBC
# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
#comp-lzo
# Set log file verbosity.
verb 3
# Silence repeating messages
;mute 20
抜粋
# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client
client
: ぼくクライアント
# Are we connecting to a TCP or
# UDP server? Use the same setting as
# on the server.
;proto tcp
proto udp
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote my-server-1 1194
;remote my-server-2 1194
接続先ホスト、ポート番号
# SSL/TLS parms.
# See the server config file for more
# description. It's best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
ca ca.crt
cert client.crt
key client.key
- CA証明書ファイル
- クライアント証明書、クライアント秘密鍵ファイル
クライアント起動
# /usr/sbin/openvpn /etc/openvpn/client.conf