#author("2018-08-01T18:08:01+09:00","","") [[FrontPage]] *ssh鍵認証 [#ca090a67] [[SSH接続の設定変更方法]] *日本語環境を使用する [#w37ff930] メッセージを日本語化するには以下のコマンドを実行し、LANG="ja_JP.UTF-8" としてください。 # localectl set-locale LANG=ja_JP.utf8 *コマンド [#n42e2836] **firewall [#x512bbc4] |起動中の確認|# firewall-cmd --state| |有効サービス|# firewall-cmd --list-all| |起動|# systemctl start firewalld| |停止|# systemctl stop firewalld| |再起動|# systemctl restart firewalld| |設定を確認|# firewall-cmd --list-all| |設定を反映|# firewall-cmd --reload| |サービス名称の一覧|# firewall-cmd --get-services| |プロトコルとポート番号|# firewall-cmd --info-service=pop3| |設定を削除する|# firewall-cmd --zone=public --remove-service=pop3| |許可ポート追加|# firewall-cmd --add-port=10000/tcp --zone=public --permanent| |許可ポート削除|# firewall-cmd --remove-port=10000/tcp --zone=public --permanent| |許可サービス追加|# firewall-cmd --permanent --zone=public --add-service=pop3| |許可サービス削除|# firewall-cmd --zone=public --remove-service=pop3| –permanent は、変更を継続的に適用するためのオプションです。OS再起動後も設定内容は持続します。 –zone=public は、ゾーンとしてpublicを使う設定です。指定できるゾーンについてはdmzやexternalなど何種類かありますが、デフォルトのpublicだけでとりあえずは事足りますので、このまま決まったお約束のオプションだと思って差し支えないでしょう。最後の –add-service=pop3 で、pop3サービスが追加されます。 |サービス名|プロトコルとポート番号| |http|TCP 80| |https|TCP 443| |pop3(メール受信)|TCP 110| |pop3s(暗号化通信によるメール受信)|TCP 995| |imap (メール受信などの操作)|TCP 143| |smtp(メール送信)|TCP 25| |smtps(暗号化通信によるメール送信)|TCP 587| |ssh、sftp|TCP 22| **rootで直接アクセス出来ないようにする [#f76ce4d5] # vi sshd_config~ PermitRootLogin no ← no に変更する **リポジトリ [#hcb66edb] |remi|# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm| –enablerepo=remi,remi-php71 の部分は、remiとremi-php71のリポジトリの使用を有効にするためのyumコマンドのオプションです。 |最新のremiパッケージリストの取得|# yum check-update --enablerepo=remi| **PHPインストール [#g72c0734] # yum install --enablerepo=remi,remi-php71 php php-devel php-mbstring php-mysqlnd php-pdo php-gd ***php.iniの編集 [#p4a0c73c] # vi php.ini post_max_size = 128M~ ・・・~ upload_max_filesize = 128M~ 上限のサイズを大きく設定することで、WordPressで大きな画像ファイルをアップロードするときにエラーにならないようにします。 **phpMyAdminインストール [#ufa9816e] # yum install --enablerepo=remi,remi-php71 phpMyAdmin |phpMyAdminアップデート|# yum update --enablerepo=remi phpMyAdmin| **環境確認 [#b7d30a82] cat /etc/redhat-release **root の リモートログイン(SSH)を禁止する [#uacd35c7] # vi /etc/ssh/sshd_config PermitRootLogin no # service restart sshd **SSHコマンドで接続ポート番号を指定する [#w2c336d3] ssh user@100.100.100.100 -p 8022 **ホストネーム変更 [#bd9ba266] # hostnamectl set-hostname centos またはファイルを直接編集 /etc/hostname **systemd systemctl [#d31ba80a] |# systemctl start| |# systemctl stop| |# systemctl reload| |# systemctl status| |# systemctl enable| |# systemctl disable| |# systemctl list-unit-files -t service| **NetworkManager [#n8b3652c] ネットワーク機能有効化 #nmcli networking on ネットワーク機能無効化 #nmcli networking off ネットワーク機能の状態を確認する # nmcli networking connectivity コマンド実行時の状態は以下のいずれかで示されます。 |nmcli networking connectivityコマンドの表示内容|意味| |ポータル(portal)|認証が必要でインターネットへ到達できない| |制限付き(limited)|ネットワークへは接続されているがインターネットへの接続性がない| |完全(full)|インターネットへの接続性がある| |不明(unknown)|ネットワークの接続性が確認できない| デバイスの一覧を表示する # nmcli device デバイスの詳細を表示する # nmcli device show [デバイス] デバイスの接続/切断を行う # nmcli device connect [デバイス] # nmcli device disconnect [デバイス] ソフトウェア(仮想)デバイスの削除 # nmcli device delete [デバイス] 接続プロファイルを一覧表示する # nmcli connection show 起動している接続プロファイルを一覧表示する # nmcli connection show --active 接続プロファイルの詳細を表示する # nmcli connection show [デバイス] 接続プロファイルの接続/切断を行う # nmcli connection up # nmcli connection down ホスト名を設定する # nmcli general hostname [ホスト名] LANインタフェースの操作を行う # nmcli connection modify [デバイス名] ipv4.addresses "[ネットワークアドレス]/[メトリック] [ゲートウェイ]" デフォルトゲートウェイのみ変更する場合 # nmcli connection modify [デバイス] ipv4.gateway "[ゲートウェイ]" サンプル # nmcli connection modify enp3s0 ipv4.addresses "192.168.0.100/24 192.168.0.1" # nmcli connection modify enp3s0 +ipv4.addresses "192.168.0.100/24 192.168.0.1" # nmcli connection modify enp3s0 -ipv4.addresses "192.168.0.100/24 192.168.0.1" DNSサーバの変更を行う # nmcli connection modify enp3s0 ipv4.dns "192.168.0.1 192.168.0.2" ルーティングテーブルはroute -nコマンドで表示できます。 # route -n **yum [#med77b82] |yum install|パッケージのインストール| |yum update|パッケージのアップデート| |yum remove|パッケージのアンインストール| |yum list installed|インストール済パッケージ| |yum list updates|アップデート可能なパッケージ| |yum list available|利用可能なパッケージ| |yum list extras|利用できないパッケージ| **rpm [#xc0383c3] rpm -qa | grep php **ss [#jf65ffb1] 「ss」コマンドは、ネットワーク通信で利用する「ソケット」についての情報などを出力するコマンドです ※1。従来はnetstatコマンドが使用されていましたが、現在はssコマンドへの移行が進んでいます。 ss [オプション] [フィルター] ***ssの主なオプション(表示対象関係) [#q0ae91fa] |短いオプション|長いオプション|意味| |-fソケット|--family ソケット|表示するソケットの種類(ファミリー)をunix、inet、inet6、link、netlinkから指定する| |-x|--unix|UNIXドメインソケットを表示(-f unix相当)| |-4|--ipv4|IPv4のソケットだけを表示(-f inet相当)| |-6|--ipv6|IPv6のソケットだけを表示(-f inet6相当)| |-0|--packet|パケットソケットを表示(-f link相当)| |-t|--tcp|TCPソケットを表示| |-u|--udp|UDPソケットを表示| |-d|--dccp|DCCPソケットを表示| |-w|--raw|RAWソケットを表示| |-a|--all|接続待ち状態(LISTEN)のソケットと接続待ち状態にないソケットの両方を表示する| |-l|--listening|接続待ち状態のソケットだけを表示する| |-N|ネームスペース|--net=ネームスペース 指定したネームスペースに切り替える| |-A|クエリ|--query=クエリ, --socket=クエリ 対象をカンマ区切りで指定する(all、inet、tcp、udp、raw、unix、packet、netlink、unix_dgram、unix_stream、unix_seqpacket、packet_raw、packet_dgramから選択)| |-F|ファイル名|--filter=ファイル名 フィルターの指定をファイルから読み込む| ***ssの主なオプション(表示内容関係) [#h950a6cc] |短いオプション|長いオプション|意味| |-n|--numeric|サービス名の名前解決を行わない(ポート番号を表示)| |-r|--resolve|名前解決を行う| |-e|--extended|詳細情報を表示| |-o|--options|タイマー情報も表示する| |-m|--memory|各ソケットのメモリの使用量も表示する| |-p|--processes|ソケットを使用しているプロセスも表示する| |-Z|--context|-pオプションに加えてセキュリティコンテキストも表示(SELinux)| |-z|--contexts|-Zオプションに加えてソケットコンテキストも表示(SELinux)| |-i|--info|内部TCPの情報も表示する| |-s|--summary|ソケットの種類ごとに本数を表示する| |-D|ファイル名|--diag=ファイル名 RAW情報をファイルに出力する(画面には何も出力しない)| **sudo [#x0fd7cac] # usermod -G wheel username # visudo ## Allows people in group wheel to run all commands # %wheel ALL=(ALL) ALL ↓ ## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL **SSL証明書 Let’s Encryptをインストール [#f6323137] # yum install certbot python2-certbot-apache # certbot --apache -d example.com Saving debug log to /var/log/letsencrypt/letsencrypt.log Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): (EMAILアドレスを入力。Let's Encryptからのお知らせを受け取るアドレスになります。) Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org ------------------------------------------------------------------------------- Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree in order to register with the ACME server at https://acme-v01.api.letsencrypt.org/directory ------------------------------------------------------------------------------- (A)gree/(C)ancel:A (規約に同意します) ------------------------------------------------------------------------------- Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about EFF and our work to encrypt the web, protect its users and defend digital rights. ------------------------------------------------------------------------------- (Y)es/(N)o: Y (Let's EncryptパートナーにEmailを公開します。したくない場合はNに。) Starting new HTTPS connection (1): supporters.eff.org Obtaining a new certificate Performing the following challenges: tls-sni-01 challenge for xxxxxxx.com We were unable to find a vhost with a ServerName or Address of example.com. Which virtual host would you like to choose? (note: conf files with multiple vhosts are not yet supported) ------------------------------------------------------------------------------- 1: ssl.conf | | HTTPS | Enabled ------------------------------------------------------------------------------- Press 1 [enter] to confirm the selection (press 'c' to cancel):1 (ssl.confを選択) Deploying Certificate for example.com to VirtualHost /etc/httpd/conf.d/ssl.conf Please choose whether HTTPS access is required or optional. ------------------------------------------------------------------------------- 1: Easy - Allow both HTTP and HTTPS access to these sites 2: Secure - Make all requests redirect to secure HTTPS access ------------------------------------------------------------------------------- Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 (httpアクセスをhttpsにリダイレクトします) Created redirect file: le-redirect-example.com.conf Rollback checkpoint is empty (no changes made?) ------------------------------------------------------------------------------- Congratulations! You have successfully enabled https://example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=example.com ------------------------------------------------------------------------------- IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/example.com/fullchain.pem. Your cert will expire on 2017-09-18. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le