Amazon Lightsailにubuntu16.04

2021年4月9日

AmazonのLightsailでubuntuのセットアップ後にやったことをメモしてみる(誰かの役に立てば幸い的な)

☆セキュリティ的に賛否両論だがrootパス設定
これはSCPからの接続でroot所有のファイルを触る場合とかを想定してです。
sudo su -
でrootになる。
passwd
でルートパスワードを設定しなおす。

☆SSH設定
vi で /etc/ssh/sshd_config を開き、一時的に(鍵設定するまでの間)パスワードでのrootログインを可能にする。
vi /etc/ssh/sshd_config
iキーを押し以下のように編集。
PermitRootLogin yes
PasswordAuthentication yes
ESCキーを押したあとに :wq で保存終了。
service sshd restart
以後はPuttyからrootでの作業とする。
ssh-keygen -t rsa
cd /
mkdir .ssh
cat /root/.ssh/id_rsa.pub >> .ssh/authorized_keys
chmod 600 /.ssh/authorized_keys
再度 /etc/ssh/sshd_config を開き以下のように編集後保存する。
#AuthorizedKeysFile %h/.ssh/authorized_keys
AuthorizedKeysFile /.ssh/authorized_keys
service sshd restart
/root/.ssh の中の id_rsa からクライアントPC側で puttygen を使い .ppkファイル を作成する。
無事rootからの秘密鍵でのputtyのログインが成功したらパスワードログイン拒否に戻すため、
/etc/ssh/sshd_config を開き以下のように編集する。
PermitRootLogin prohibit-password
または
PermitRootLogin without-password
PermitEmptyPasswords no
PasswordAuthentication no
保存したらsshdを再起動する。
service sshd restart

☆Japaneseパッケージの追加
wget -q https://www.ubuntulinux.jp/ubuntu-ja-archive-keyring.gpg -O- | sudo apt-key add -
wget -q https://www.ubuntulinux.jp/ubuntu-jp-ppa-keyring.gpg -O- | sudo apt-key add -
wget https://www.ubuntulinux.jp/sources.list.d/xenial.list -O /etc/apt/sources.list.d/ubuntu-ja.list

apt-get update

☆時刻サーバーのセットアップ
apt-get install ntp
/etc/ntp.conf を開き以下の部分を#を付けてコメントにした後、その下も以下のとおりに追加
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst
#pool ntp.ubuntu.com
server ntp.nict.jp iburst
server ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
server ntp3.jst.mfeed.ad.jp iburst
restrict 10.0.0.0 mask 255.255.255.0 nomodify notrap
UDP123番ポートを開けてから時刻サーバーの再起動。
service ntp restart

☆32bitプログラム用モジュールのインストール
dpkg --add-architecture i386
apt-get update
apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386

ローカルの別PCから視覚的に設定なんやら見たい(またはSSに撮りたい)時のために
☆Webminのインストール
apt-get install python apt-show-versions libapt-pkg-perl libauthen-pam-perl libio-pty-perl libnet-ssleay-perl unzip
curl -L -O http://www.webmin.com/download/deb/webmin-current.deb
dpkg -i webmin-current.deb
systemctl restart webmin

☆MySQLのインストール
apt-get install mysql-server
mysqlのrootパスを作成するために入力画面が2回出るので入力する

☆MySQLの設定変更
/etc/mysql/mysql.conf.d/mysqld.cnfを開き
[mysqld]のところで
character-set-server = utf8
skip-character-set-client-handshake

一番下に以下を追記する。
[mysqldump]
default-character-set=utf8
[mysql]
default-character-set=utf8

☆Web環境やMCのインストール
apt-get install apache2
/etc/apache2/sites-available の中の000-default.confを開き、公開したい設定へ変更する
a2dissite 000-default.conf
a2ensite 000-default.conf
等のコマンドで変えた設定を反映させる
add-apt-repository ppa:ondrej/php
apt update
apt install php5.6 php5.6-gd php5.6-mbstring php5.6-cgi php5.6-imap php-pear php5.6-xmlrpc php5.6-xsl
apt install php5.6-curl php5.6-mcrypt libapache2-mod-php5.6 php5.6-mcrypt php5.6-mysql
apt-get install mc imagemagick

☆Web環境の設定
/etc/php/php5/apache2/php.ini を開き以下の箇所を変更する
expose_php = Off
date.timezone = Asia/Tokyo

☆PhpMyAdminのインストール
apt-get install phpmyadmin
myphpadminを表示するWebサーバーの選択が出るのでapache2を指定する
その次の質問はYesを押す
Mysqlのrootパスを2回聞かれるので入力する
ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
a2enconf phpmyadmin
php5enmod mcrypt
service apache2 reload

☆その他アプリを導入した場合に
起動スクリプトが無ければ /etc/init.d に作る
作った /etc/init.d のスクリプトを以下のようにスタートアップ登録する
insserv -d 作ったスクリプト名

Linux

Posted by boomboom