2019年5月30日木曜日

ssh keysを作ってみた。(ssh 公開鍵認証)

【AWS EC2  guacamole 】

# useradd takahab
# passwd takahab
$ su - takahab
$ mkdir .ssh
$ chmod 0700 .ssh
$ cd .ssh
$ ssh-keygen -t rsa -b 4096 -m PEM
$ vi authorized_keys     <-- id_rsa.pubをコピー
$ chmod 0600  authorized_keys

※ keepAlive
$ ssh -o ServerAliveInterval=60  -p 22 target_host

# vi /etc/ssh/sshd_config
ClientAliveInterval 120
ClientAliveCountMax 3


【クライアント側】
[$ ssh-keygen -t ed25519]      # githubの場合

※ 一時的にサーバ側でパス認証を許可して上で実施。

$ ssh-keygen -t rsa -b 4096 -C "email@example.com"
$ ssh-keygen -l -f ~/.ssh/id_rsa.pub        # 確認
$ ssh-copy-id -i ~/.ssh/id_rsa.pub -p 65522 $REMOTE
$ ssh -i id_rsa -p 65522 $REMOTE

※接続できない場合は、
$ ssh -v       -p 65522 $REMOTE
$ ssh -vvv  -p 65522 $REMOTE
ログ確認
#  vi /var/log/secure
# vi  /var/log/ssh/sshd.log

【サーバ側】
$ su
# vi /etc/ssh/sshd_config
PermitRootLogin を no                                          # root ログイン禁止
PasswordAuthentication no                                # パスワード認証禁止(公開鍵認証のみ) 
PermitEmptyPasswords  no                                # パスワード無し禁止( パスワード認証の場合)
# systemctl restart sshd

ーーーーーー以下 参考ーーーーーーーーー
【サーバ側】
$ cp id_rsa.pub
$ vi  ~/.ssh/authorized_keys
id_rsa.pub をコピー&ペイスト 
$ chmod 600 authorized_keys

【作成】
# useradd user
$ cd 
$ ssh-keygen -t rsa -b 4096 -C "email@example.com"
【確認】
$ ssh-keygen -l -f ~/.ssh/id_rsa.pub

【配信】
#ssh-copy-id -i ~/.ssh/id_rsa.pub root@remote.com -p 22

久しぶりに公開鍵を作ってみた。

$ openssl genrsa 4096 > private-key.pem
$ openssl rsa -in private-key.pem -pubout -out public-key.pem

$ openssl rsa -in private-key.pem -text -noout
$ openssl rsa -pubin -in public-key.pem -text -noout

2019年5月15日水曜日

goaccessを使ってみた。

# yum install goaccess
# vi /etc/goaccess.conf
time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"

# goaccess /var/log/httpd/access_log*
# goaccess /var/log/httpd/access_log* >/var/www/html/reports.html

2019年5月7日火曜日

mysqldが起動できない。 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

[System][MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 20744
[System][MY-013381] [Server] Server upgrade from '80015' to '80016' started.
[ERROR][MY-013384] [Server] Could not create server upgrade info file at '/var/lib/mysql/'.
[ERROR][MY-013380] [Server] Failed to upgrade server.
[ERROR][MY-010119] [Server] Aborting


【対処】
# mv /var/lib/mysql/mysql_upgrade_info /var/lib/mysql/mysql_upgrade_info.bak
# systemctl start mysqld


# vi /var/log/mysqld.log

[System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 21873
[System] [MY-013381] [Server] Server upgrade from '80015' to '80016' started.
[System] [MY-013381] [Server] Server upgrade from '80015' to '80016' completed.

無事起動した。
※8.0.16からデータベースのアップグレードが自動になったもよう。

ssh 中継

【AWS EC2中継】
$ vi  ~/.ssh/config    << __EOF__
host aws.step
  HostName xx.xx.xx.xx
  Port 22
  User ec2-user
  IdentityFile ~/.ssh/step.pem

Host aws.utlsv
  HostName xx.xx.xx.xx
  Port 22
  User ec2-user
  ProxyCommand ssh aws.step -W %h:%p
  IdentityFile ~/.ssh/utlsv.pem
__EOF__

接続したいホストと中継サーバ間にトンネル生成
$ ssh www.gateway.com -R 10022:192.168.1.100:22
※autosshコマンドでを使えば、切断時も自動再接続してくれる。

遠隔から
$ ssh www.gateway.com
$ ssh localhost -p 10022

tmux仮想端末でマルチ画面

cntl+b c   ウィンドウ作成
cntl+b 1-n ウィンドウ指定
cntl+b p   ウィンドウ切り替え



データベース開発ツールDBeaverのインストール

https://dbeaver.io/
上記からDBeaver 6.0.4をダウンロード

# rpm -ivh dbeaver-ce-6.0.4-stable.x86_64.rpm

jdbcドライバをインストール。
# cp ojdbc6.jar /opt/libs/oracle/ojdbc6.jar


バージョンアップ
# rpm -qa |grep dbea
dbeaver-ce-6.0.4-stable.x86_64
# rpm -qi dbeaver-ce
# rpm -Uvh dbeaver-ce-6.1.1-stable.x86_64.rpm

[splash]
~/.eclipse/org.jkiss.dbeaver.product_22.3.2_302967072_linux_gtk_x86_64/configuration/org.eclipse.equinox.launcher/org.jkiss.dbeaver.ui.app.standalone_22.3.2.202301060755



シャットダウン時の後処理 (shutdown)

# vi /etc/systemd/system/drop.service [Unit] Description= stop httpgwd DefaultDependencies=no Before=shutdown.target RefuseManualStart=true ...