ユーザ用ツール

サイト用ツール


サイドバー

Index

はじめてのおつかい






DokuWiki整形記法


PlayGround



tipsmemo:tips

tips

sha512でハッシュされたsaltつきパスワードを生成する

perl

$ perl -e 'print crypt("password", "\$6\$SALTsalt");'
$6$SALTsalt$UiZikbV3VeeBPsg8./Q5DAfq9aj7CVZMDU6ffBiBLgUEpxv7LMXKbcZ9JSZnYDrZQftdG319XkbLVMvWcF/Vr/

openssl1)

$ openssl passwd -6 -salt SALTsalt password
$6$SALTsalt$UiZikbV3VeeBPsg8./Q5DAfq9aj7CVZMDU6ffBiBLgUEpxv7LMXKbcZ9JSZnYDrZQftdG319XkbLVMvWcF/Vr/

正規表現

開いているポートを確認する

netstat

$ netstat -an | grep LISTEN
tcp4    0    0    *.80    *.*    LISTEN
......

pidも見る2)

$ netstat -apn | grep LISTEN
tcp     0    0 0.0.0.0:80  0.0.0.0:*  LISTEN  31xxx/nginx: worker
......
  • -aオプション→現在の全ての接続を表示。指定しないとESTABLISHEDのみ表示
  • -pオプション→プロセスIDとプロセス名を表示
  • -nオプション→ホスト名で表示せず、IPアドレスで表示する(名前解決しない)

lsof

ファイル指定

# lsof /var/log/messages 
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
rsyslogd  949 root    1w   REG  202,1   161802 266276 /var/log/messages
tail     1966 root    3u   REG  202,1   161802 266276 /var/log/messages

port指定

# lsof -i:80,433
COMMAND   PID  USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
nginx   16884  root    7u  IPv4 8072178      0t0  TCP *:http (LISTEN)
nginx   16886 nginx    7u  IPv4 8072178      0t0  TCP *:http (LISTEN)
...

プロセス名指定

#  lsof -c nginx
COMMAND   PID  USER   FD   TYPE             DEVICE SIZE/OFF    NODE NAME
nginx   16884  root  cwd    DIR              202,1     4096       2 /
nginx   16884  root  rtd    DIR              202,1     4096       2 /
nginx   16884  root  txt    REG              202,1   884504   25102 /usr/sbin/nginx
...

PID指定

lsof -p 16884
COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF    NODE NAME
nginx   16884 root  cwd    DIR              202,1     4096       2 /
nginx   16884 root  rtd    DIR              202,1     4096       2 /
nginx   16884 root  txt    REG              202,1   884504   25102 /usr/sbin/nginx
...

ユーザ指定

# lsof -u user
COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF   NODE NAME
sshd    1663 ec2-user  cwd    DIR              202,1     4096      2 /
sshd    1663 ec2-user  rtd    DIR              202,1     4096      2 /
sshd    1663 ec2-user  txt    REG              202,1   571224  26039 /usr/sbin/sshd
...

コマンドを連結 「;」「&」「&&」「||」の違い

;(セミコロン)

前のコマンドが終わり次第、次のコマンドが実行

&(アンパサンド)

前のコマンドの完了を待たない

&&

前のコマンドがうまく終了した(終了ステータスが0)時に、次のコマンドを実行

||

前のコマンドに失敗(終了コード0以外)したら、次のコマンドを実行

コマンドラインでhash

$ echo -n 'hoge' | shasum -a 1
31f30ddbcb1bf8446576f0e64aa4c88a9f055e3c  -

$ echo -n 'hoge' | shasum -a 256
ecb666d778725ec97307044d642bf4d160aabb76f56c0069c71ea25b1e926825  -

$  echo -n "hoge" | openssl sha1
(stdin)= 31f30ddbcb1bf8446576f0e64aa4c88a9f055e3c

* -n:改行コードを出力しない
* -a:アルゴリズム

GNU拡張

$ openssl passwd -1 -salt "SALTsalt" "test"
$1$SALTsalt$CEvzkj.qgOcLTyU2B5Kg3.

$ openssl passwd -apr1 -salt "SaltsALT" "p@ssw0rd"
$apr1$SaltsALT$51lBhVKD0vAdzxUx/rXqY/

perl

$ perl -e 'print crypt("test", "\$6\$SALTsalt");'
$6$SALTsalt$gH47I0mRGadJVVlIpeTxVlYw.SjkPOZ7lJoGkqOyhyeUJ7PV5QWuYpIG6D5ggew6RXLpl1eA72TpgX5pGDpr/.

python

$ python -c "import crypt, getpass, pwd; print crypt.crypt('test','\$6\$SALTsalt\$')"
$6$SALTsalt$gH47I0mRGadJVVlIpeTxVlYw.SjkPOZ7lJoGkqOyhyeUJ7PV5QWuYpIG6D5ggew6RXLpl1eA72TpgX5pGDpr/.

UUID生成

$ uuidgen -r

-r を付けないとランダム(UUID Version4)にならないので注意(@FreeBSD)

ダミーファイルを作る

10Mbyte

# dd if=/dev/zero of=10M.txt bs=1M count=10

Linuxならこれも3)

# fallocate -l 10M 10M.txt

SSHでパイプしつつデータ転送

cat hoge.txt | ssh host " cat > /tmp/huga.txt"

diff コマンドで横並びで表示したい

diff -y path/to/file1 path/to/file2

変更行のみを表示したい

diff -y --suppress-common-lines path/to/file1 path/to/file2

Gitでcheckout時にPermission Denied

どうも、SourceTreeかTortoiseGitがつかんで離していない模様。
再起動で治った

コミット時に書いてほしいこと

  • どのような変更ですか?
  • この変更によって,どんなことが起きますか?
  • なぜその変更が必要でしたか?
  • 参考URLなど(あれば)

tmpwatchコマンド

使い所

  • ある一定の時間を過ぎたファイルやディレクトリを削除したい時
  • 一時ファイルを定期的に削除したい時
  • 定期的に◯時間アクセスがないログファイルとかを削除したい時

ハードウェア情報

dmidecodeが便利4)

メモリ情報

# dmidecode --type memory
Memory Device
    Array Handle: 0x1000
    Error Information Handle: Not Provided
    Total Width: 72 bits
    Data Width: 64 bits
    Size: 2048 MB
    Form Factor: DIMM
    Set: 4
    Locator: DIMM_A7 
    Bank Locator: Not Specified
    Type: DDR3
    Type Detail: Synchronous Registered (Buffered)
    Speed: 1333 MT/s
    Manufacturer: 00CExxxxxxxxx
    Serial Number: 83xxxxxx
    Asset Tag: 02113611
    Part Number: M393xxxxxxxxx-xxx
    Rank: 2

CPU情報

# dmidecode --type processor
Processor Information
    Socket Designation: CPU1
    Type: Central Processor
    Family: Xeon
    Manufacturer: Intel
    Signature: Type 0, Family 6, Model 44, Stepping 2
    Flags:
        FPU (Floating-point unit on-chip)
        ......
    Version: Intel(R) Xeon(R) CPU           L5639  @ 2.13GHz
    Voltage: 1.2 V
    External Clock: 5860 MHz
    Max Speed: 3600 MHz

各種サーバの設定ファイルの書式チェックの方法

apache

/usr/local/sbin/httpd -S
or
apachectl configtest

nginx

# nginx -t

postfix

# postfix check

何も出なければOK

lighttpd

# lighttpd -t -f /usr/local/etc/lighttpd/lighttpd.conf

sshd

# sshd -t

何も出なければOK

dovecot

# doveconf -n

PHP

phpinfo.php
<?php phpinfo(); ?>

Rspamd

rspamadm configtest

換算表(サブネットマスク)

IPアドレス数サブネットマスクビットマスク
1255.255.255.25532
2255.255.255.25431
4255.255.255.25230
8255.255.255.24829
16255.255.255.24028
32255.255.255.22427
64255.255.255.19226
128255.255.255.12825
256255.255.255.024
512255.255.254.023
1,024255.255.252.022
2,048255.255.248.021
4,096255.255.240.020
8,192255.255.224.019
16,384255.255.192.018
32,768255.255.128.017
65,536255.255.0.016
131,072255.254.0.015
262,144255.252.0.014
524,288255.248.0.013
1,048,576255.240.0.012
2,097,152255.224.0.011
4,194,304255.192.0.010
8,388,608255.128.0.09
16,777,216255.0.0.08
33,554,432254.0.0.07
67,108,864252.0.0.06
134,217,728248.0.0.05
268,435,456240.0.0.04
536,870,912224.0.0.03
1,073,741,824192.0.0.02
2,147,483,648128.0.0.01
4,294,967,2960.0.0.00
1)
1.1.1以降
2)
freeBSDでは動作しない
3)
ddより早い
4)
要インストール
tipsmemo/tips.txt · 最終更新: 2024/03/16 18:24 by hayashi