LoginSignup
31
22

More than 3 years have passed since last update.

iPadで動くLinuxエミュレーター「iSH」がすごいと私の中で話題に

Posted at

iSHセットアップ

apkをインストール

標準ではパッケージマネージャーのapkがインストールされていないのでインストールします。

$ wget -qO- http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86/apk-tools-static-2.10.5-r1.apk | tar -xz sbin/apk.static && ./sbin/apk.static add apk-tools && rm sbin/apk.static && rmdir sbin 2> /dev/null

apkの更新

$ apk update
$ apk upgrade

最低限色々入れてみる

$ apk add zsh vim git openssh

デフォルトシェル変更

$ vim /etc/passwd
# 変更前
root:x:0:0:root:/root:/bin/ash
# 変更後
root:x:0:0:root:/root:/bin/zsh

変更後はiSHを再起動します。
するとプロンプトが\h:\w\$と表示され見辛いのでプロンプトを変えちゃいましょう。
全ユーザーで共通にしたいので/etc/zshrcを作ります。

setopt PROMPT_SUBST     # allow funky stuff in prompt

if [ "$USER" = "root" ]; then
    color="red"         # root is red, user is cyan
else
    color="cyan"
fi;


local ok_yuno="%F{yellow}✘╹◡╹✘%f"
local bad_yuno="%F{red}✘>﹏<✘%f"
local command_line="
%F{green}%B%*%b%f %F{$color}%B%n@%m%b%f %F{green}%B%~%b%f
%(?.${ok_yuno}.${bad_yuno}) %F{yellow}%B%#%b%f "

export PROMPT="${command_line}"

ついでに/etc/vimrc

syntax enable

set number
set title
set cursorline
set virtualedit=onemore
set showmatch
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent
set hlsearch
nmap <Esc><Esc> :nohlsearch<CR><Esc>

set fenc=utf-8
set encoding=utf-8
scriptencoding utf-8
set ambiwidth=double

inoremap { {}<Left>
inoremap {<Enter> {}<Left><CR><ESC><S-o>
inoremap ( ()<ESC>i
inoremap (<Enter> ()<Left><CR><ESC><S-o>
inoremap [ []<Left>
inoremap ' ''<Left>
inoremap " ""<Left>

nnoremap j gj
nnoremap k gk
nnoremap <down> gj
nnoremap <up> gk

バックグラウンドでiSHを起動したままにする

魔法のおまじないです。

$ cat /dev/location > /dev/null &

次にiPadOSの設定アプリでiSHの位置情報利用を常に許可します。

SSHで好きなクライアントからiSHにログインする

iSHのターミナルはちょっと味気ないので普段使い慣れてるクライアントから操作できたら嬉しいですよね。
ここではみのりんおすすめのBlink Shellを使ってiSHを操作してみます。

iSHで準備

Port 22000 # 同じデバイスからは22番でアクセスできない
PermitRootLogin yes # あとでNoに変更
PubkeyAuthentication yes
PasswordAutentication yes # あとでNoに変更
ClientAliveInterval 60 # SSHが途切れないようにお好みで
ClientAliveCountMax 60
$ passwd # rootパスワードを決める
$ ssh-keygen -A
$ /usr/sbin/sshd

あとはお好きなクライアントから接続するだけです(o・ω・o)

ssh root@localhost -p 22000

一般ユーザー追加とか

$ adduser -s /bin/zsh minorin
$ addgroup minorin wheel

sudoをインストール

$ apk add sudo
$ visudo
# コメントアウトを外す
%wheel ALL=(ALL) ALL

SSH設定

鍵作成

$ su minorin
$ chmod 755 /home/minorin
$ cd
$ mkdir .ssh
$ chmod 700 .ssh
$ cd .ssh
$ touch authorized_keys
$ chmod 600 authorized_keys
$ ssh-keygen
$ chmod 600 id_rsa

このあとautorized_keysにクライアントの公開鍵をコピペします。

sshd_config設定

PermitRootLogin no
PasswordAutentication no
AddressFamily inet
UseDNS no
$ sudo /usr/sbin/sshd

あとはいつものクライアントから鍵認証でSSHできることを確認するだけです。

ssh minorin@localhost -p 22000

openrcとか

$ apk add openrc
$ rc-update add sshd

これでsshdが自動起動されるはずだけどうまくいかない( ;∀;)

code-serverのインストール

$ apk add alpine-sdk libstdc++ libc6-compat npm libx11-dev libxkbfile-dev libsecret-dev python3
$ npm config set unsafe-perm true
$ npm config set python python3
$ npm install -g @google-cloud/logging@4.5.2
$ npm install -g code-server
npm WARN @coder/logger@1.1.11 requires a peer of @google-cloud/logging@^4.5.2 but none is installed. You must install peer dependencies yourself.

npm ERR! code ENOENT
npm ERR! syscall rename
npm ERR! path /usr/lib/node_modules/code-server/node_modules/tar-fs/node_modules/chownr
npm ERR! dest /usr/lib/node_modules/code-server/node_modules/tar-fs/node_modules/.chownr.DELETE
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, rename '/usr/lib/node_modules/code-server/node_modules/tar-fs/node_modules/chownr' -> '/usr/lib/node_modules/code-server/node_modules/tar-fs/node_modules/.chownr.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-**-*****_**_**_****-debug.log

ダメでした( ;∀;)

次回予告

とりあえずVNCの設定とかやってみるつもりです。

31
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
22