FrontPage

ssh鍵認証

SSH接続の設定変更方法

コマンド

firewall

起動中の確認# 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サービスが追加されます。

サービス名プロトコルとポート番号
httpTCP 80
httpsTCP 443
pop3(メール受信)TCP 110
pop3s(暗号化通信によるメール受信)TCP 995
imap (メール受信などの操作)TCP 143
smtp(メール送信)TCP 25
smtps(暗号化通信によるメール送信)TCP 587
ssh、sftpTCP 22

rootで直接アクセス出来ないようにする

# vi sshd_config

PermitRootLogin no ← no に変更する

リポジトリ

–enablerepo=remi,remi-php71 の部分は、remiとremi-php71のリポジトリの使用を有効にするためのyumコマンドのオプションです。

最新のremiパッケージリストの取得# yum check-update --enablerepo=remi

PHPインストール

# yum install --enablerepo=remi,remi-php71 php php-devel php-mbstring php-mysqlnd php-pdo php-gd

php.iniの編集

# vi php.ini

post_max_size = 128M
・・・
upload_max_filesize = 128M

上限のサイズを大きく設定することで、WordPressで大きな画像ファイルをアップロードするときにエラーにならないようにします。

phpMyAdminインストール

# yum install --enablerepo=remi,remi-php71 phpMyAdmin

phpMyAdminアップデート# yum update --enablerepo=remi phpMyAdmin

SSL証明書 Let’s Encryptをインストール

# 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

環境確認

cat /etc/redhat-release

root の リモートログイン(SSH)を禁止する

# vi /etc/ssh/sshd_config

PermitRootLogin no

# service restart sshd

SSHコマンドで接続ポート番号を指定する

ssh user@100.100.100.100 -p 8022

ホストネーム変更

# hostnamectl set-hostname centos

またはファイルを直接編集 /etc/hostname

systemctl

# systemctl start
# systemctl stop
# systemctl reload
# systemctl status
# systemctl enable
# systemctl disable
# systemctl list-unit-files -t service

yum

yum installパッケージのインストール
yum updateパッケージのアップデート
yum removeパッケージのアンインストール
yum list installedインストール済パッケージ
yum list updatesアップデート可能なパッケージ
yum list available利用可能なパッケージ
yum list extras利用できないパッケージ

rpm

rpm -qa | grep php

ss

「ss」コマンドは、ネットワーク通信で利用する「ソケット」についての情報などを出力するコマンドです ※1。従来はnetstatコマンドが使用されていましたが、現在はssコマンドへの移行が進んでいます。

ss [オプション] [フィルター]

ssの主なオプション(表示対象関係)

短いオプション長いオプション意味
-fソケット--family ソケット表示するソケットの種類(ファミリー)をunix、inet、inet6、link、netlinkから指定する
-x--unixUNIXドメインソケットを表示(-f unix相当)
-4--ipv4IPv4のソケットだけを表示(-f inet相当)
-6--ipv6IPv6のソケットだけを表示(-f inet6相当)
-0--packetパケットソケットを表示(-f link相当)
-t--tcpTCPソケットを表示
-u--udpUDPソケットを表示
-d--dccpDCCPソケットを表示
-w--rawRAWソケットを表示
-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の主なオプション(表示内容関係)

短いオプション長いオプション意味
-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

# 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

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS