理想未来ってなんやねん

娘可愛い。お父さん頑張る。

cygwinでの環境構築

EveryPad Proで久々にWindowsを使っています。
久々すぎて色々変わっているので環境構築についてメモしておきます。

コマンドによるパッケージ管理ツール

yumのようなコマンドで管理できるパッケージ管理ツールとしてはapt-cygというものがあるらしい。
インストールは簡単。ダウンロードしてパスの通ったディレクトリに入れておくだけ。

wget https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg
chmod 755 apt-cyg
mv apt-cyg /usr/local/bin/

topコマンド

topコマンドがない。
コマンドを叩いたときに寂しい思いをするので入れておく。

apt-cyg install procps

clearコマンド

clearコマンドはncursesをインストールすると使えるようになる。

apt-cyg install ncurses

ifconfig、ping

windows標準のコマンドを使用することになるが、cygwin環境で使用すると文字化けする。
パイプ出力したものをiconvで変換しても良いけど、今回はcocotという文字変換するツールをインストールすることにした。

apt-cyg install automake
git clone https://github.com/vmi/cocot.git
cd cocot
./configure
make && make install

~/.bashrcに追記しておく。

alias ifconfig="cocot ipconfig"
alias ping="cocot ping"
alias arp="cocot arp"
alias nslookup="cocot nslookup"
alias traceroute="cocot tracert"
alias route="cocot route"
alias netstat="cocot netstat"

reboot、shutdown

shutdownパッケージをインストールすると、コマンドでshutdown、rebootができるようになる。

apt-cyg  install shutdown 

sshd

外出用にEveryPad Proを購入したけれど、家にいるときはMacの方で設定したい。
sshdを立ちあげてリモートで使えるようにしておく。

設定はssh-host-configコマンドで行う。

ssh-host-config -y

途中、sshdを動作させるユーザーのパスワードの入力を求められるので適切なパスワードを設定する。


設定を書き換える。
標準ポートの22は嫌なので、10022にしておく。

sed -i -e 's/^#?Port .*/Port 10022/g' \
       -e 's/^#?PermitRootLogin .*/PermitRootLogin without-password/g' \
       -e 's/^#?PasswordAuthentication .*/PasswordAuthentication no/g' \
       -e 's/^#?UseDNS .*/UseDNS no/g' \
       -e 's/^#?ClientAliveInterval .*/ClientAliveInterval 10/g' \
       -e 's/^#?ClientAliveCountMax .*/ClientAliveCountMax 12/g' \
       /etc/sshd_config

cygrunsrvでsshdを起動する。

cygrunsrv -S sshd

netsh advfirewallコマンドでWindowsファイアウォールの設定を変更しsshで使用するポートを開けておく。

netsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=tcp localport=10022 profile=private

秘密鍵、公開鍵の生成

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/XXXXXX/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/XXXXXX/.ssh/id_rsa.
Your public key has been saved in /home/XXXXXX/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:urCAmSVIh3OMv6CPiSVFloO7T7N2A5nMTQFUBA5R2UQ XXXXXX@XXXXXX
The key's randomart image is:
+---[RSA 2048]----+
|o+=XE            |
| +=.o            |
|.=*+ .           |
|o+=..            |
|++o*    S        |
|.OB o  .         |
|B =o. .          |
|.O.+oo .         |
|+.+....          |
+----[SHA256]-----+

公開鍵をauthorized_keysに追記しておく。

cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys

秘密鍵、~/.ssh/id_rsaは接続元のPCにコピーする。

とりあえず、本日のところはここまで。