mosh – matoken's blog https://matoken.org/blog Is there no plan B? Tue, 12 Jul 2022 14:49:28 +0000 ja hourly 1 https://wordpress.org/?v=7.0 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg mosh – matoken's blog https://matoken.org/blog 32 32 moshに繋がらなくなった(localeが不足していた) https://matoken.org/blog/2022/07/12/not-connected-to-mosh/ https://matoken.org/blog/2022/07/12/not-connected-to-mosh/#respond Tue, 12 Jul 2022 14:49:26 +0000 http://matoken.org/blog/?p=3718

リモートのmoshに繋がらなくなってしまいました.sshの認証後に失敗しています.
sshでは繋がります.

以下はmoshでssh認証以降のメッセージです.接続元で ja_JP.UTF-8 を使っているのでmoshサーバでもそれを使おうとして見つからずに失敗していそうです.

Authenticated to 192.0.2.5 (via proxy) using "publickey".
bash: warning: setlocale: LC_ALL: cannot change locale (ja_JP.UTF-8)
The locale requested by LC_ALL=ja_JP.UTF-8 isn't available here.
Running `locale-gen ja_JP.UTF-8' may be necessary.

The locale requested by LC_ALL=ja_JP.UTF-8 isn't available here.
Running `locale-gen ja_JP.UTF-8' may be necessary.

mosh-server needs a UTF-8 native locale to run.

Unfortunately, the local environment (LC_ALL=ja_JP.UTF-8) specifies
the character set "US-ASCII",

The client-supplied environment (LC_ALL=ja_JP.UTF-8) specifies
the character set "US-ASCII".

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=ja_JP.UTF-8
LANGUAGE=
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
LC_COLLATE="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_PAPER="ja_JP.UTF-8"
LC_NAME="ja_JP.UTF-8"
LC_ADDRESS="ja_JP.UTF-8"
LC_TELEPHONE="ja_JP.UTF-8"
LC_MEASUREMENT="ja_JP.UTF-8"
LC_IDENTIFICATION="ja_JP.UTF-8"
LC_ALL=ja_JP.UTF-8
Connection to 192.0.2.5 closed.
Transferred: sent 3232, received 4688 bytes, in 3.3 seconds
Bytes per second: sent 975.2, received 1414.6
/usr/bin/mosh: Did not find mosh server startup message. (Have you installed mosh on your server?)

試しに LC_ALL=en_US.UTF-8 を渡すと接続できました.

$ LC_ALL=en_US.UTF-8 mosh $SERVER

sshで接続して確認すると en_US.UTF-8 しか設定されていません.

$ grep -v ^# /etc/locale.gen


en_US.UTF-8 UTF-8

ja_JP.UTF-8 とついでに ja_JP.EUC-JP を追加して, locale-gen コマンドでlocaleを生成しました.

$ sudo vi /etc/locale.gen
$ sudo git diff /etc/locale.gen
diff --git a/locale.gen b/locale.gen
index afb6141..0f91c36 100644
--- a/locale.gen
+++ b/locale.gen
@@ -286,7 +286,7 @@ en_US.UTF-8 UTF-8
 # it_IT.UTF-8 UTF-8
 # it_IT@euro ISO-8859-15
 # iu_CA UTF-8
-# ja_JP.EUC-JP EUC-JP
-#  ja_JP.UTF-8 UTF-8
+ja_JP.EUC-JP EUC-JP
+ja_JP.UTF-8 UTF-8
 # ka_GE GEORGIAN-PS
 # ka_GE.UTF-8 UTF-8
 # kab_DZ UTF-8
$ sudo locale-gen
Generating locales (this might take a while)...
  en_US.UTF-8... done
  ja_JP.EUC-JP... done
  ja_JP.UTF-8... done
Generation complete.

この状態で再度 LC_ALL=ja_JP.UTF-8 の状態でmoshで接続してみるとうまく接続できるようになりました :)
以前は繋げていたのでいつの間にか /etc/locale.gen を書き換えてしまっていた?

/etc はetckeeperでgit管理しているので探してみると,locales 2.28-10locales 2.28-10+deb10u1 の更新時に ja_JP.UTF-8 UTF-8 がコメントアウトされていました.確認不足ですね><

環境
$ dpkg-query -W mosh locales
locales 2.28-10+deb10u1
mosh    1.3.2-2.1+b1
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ arch
x86_64
]]>
https://matoken.org/blog/2022/07/12/not-connected-to-mosh/feed/ 0
moshが起動しなくなって困る https://matoken.org/blog/2022/02/28/mosh-does-not-start/ https://matoken.org/blog/2022/02/28/mosh-does-not-start/#respond Mon, 28 Feb 2022 14:33:57 +0000 http://matoken.org/blog/?p=3450

Debian sid amd64環境でmoshが動かなくなった.

$ mosh
IO.c: loadable library and perl binaries are mismatched (got handshake key 0xed00080, needed 0xeb00080)

mosh-clientは動くけど ~/.ssh/config を見てくれないので面倒

$ mosh-client
mosh-client (mosh 1.3.2) [build mosh 1.3.2]
Copyright 2012 Keith Winstein <mosh-devel@mit.edu>
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Usage: mosh-client [-# 'ARGS'] IP PORT
       mosh-client -c

mosh は perl script

$ file /bin/mosh
/bin/mosh: Perl script text executable
$ grep -v ^# /bin/mosh | head


use 5.8.8;

use warnings;
use strict;
use Getopt::Long;
use IO::Socket;
use Text::ParseWords;
use Socket qw(IPPROTO_TCP);

mosh-client はelf

$ file /bin/mosh-client
/bin/mosh-client: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=9145424edb62c61b0081efeaa68ea20a25a73e5f, for GNU/Linux 3.2.0, stripped

sidだしPerlのアップデートもあったのでそのせいかなと思っていたけどしばらく経っても直らない.

cpanやcpanmも動かない.cpanは ~/perl5 を見ている.
最近Debian sidのPerlのバージョンが上がったのに ~/perl5 を更新していないので不整合となっていたよう.
一旦 ~/perl5 を退避して動作するように.
ディストリビューションアップデート時などにも嵌りそう.

$ cpanm --list
IO.c: loadable library and perl binaries are mismatched (got handshake key 0xed00080, needed 0xeb00080)
$ which cpan
/home/matoken/perl5/bin/cpan
$ which cpan
/home/matoken/perl5/bin/cpan
$ mosh
Usage: /usr/bin/mosh [options] [--] [user@]host [command...]
        --client=PATH        mosh client on local machine
                                (default: "mosh-client")
        --server=COMMAND     mosh server on remote machine
                                (default: "mosh-server")

        --predict=adaptive      local echo for slower links [default]
-a      --predict=always        use local echo even on fast links
-n      --predict=never         never use local echo
        --predict=experimental  aggressively echo even when incorrect

-4      --family=inet        use IPv4 only
-6      --family=inet6       use IPv6 only
        --family=auto        autodetect network type for single-family hosts only
        --family=all         try all network types
        --family=prefer-inet use all network types, but try IPv4 first [default]
        --family=prefer-inet6 use all network types, but try IPv6 first
-p PORT[:PORT2]
        --port=PORT[:PORT2]  server-side UDP port or range
                                (No effect on server-side SSH port)
        --bind-server={ssh|any|IP}  ask the server to reply from an IP address
                                       (default: "ssh")

        --ssh=COMMAND        ssh command to run when setting up session
                                (example: "ssh -p 2222")
                                (default: "ssh")

        --no-ssh-pty         do not allocate a pseudo tty on ssh connection

        --no-init            do not send terminal initialization string

        --local              run mosh-server locally without using ssh

        --experimental-remote-ip=(local|remote|proxy)  select the method for
                             discovering the remote IP address to use for mosh
                             (default: "proxy")

        --help               this message
        --version            version and copyright information

Please report bugs to mosh-devel@mit.edu.
Mosh home page: https://mosh.org

環境

$ dpkg-query -W mosh perl
mosh    1.3.2-2.1+b3
perl    5.34.0-3
$ lsb_release -dr
Description:    Debian GNU/Linux bookworm/sid
Release:        unstable
$ arch
x86_64
]]>
https://matoken.org/blog/2022/02/28/mosh-does-not-start/feed/ 0
mosh 1.3.0をDropbear sshdで利用してみる https://matoken.org/blog/2017/03/28/try-dropbear-sshd-with-mosh-1-3-0/ https://matoken.org/blog/2017/03/28/try-dropbear-sshd-with-mosh-1-3-0/#respond Mon, 27 Mar 2017 22:49:07 +0000 http://matoken.org/blog/?p=1571 moshの1.3.0がリリースされました.

moshはsshを置き換えようとしているソフトウェアで,ネットワークが遅いときにローカルエコーを表示したり,ネットワークが切り替わってもローミングしたりと便利なソフトウェアです.(NotePCで接続してサスペンドして別のネットワークでレジュームしてもすぐに使っていた端末にアクセスできる)

1.3.0でなにかおもしろい機能が増えたりしていないかなと眺めていると

  * Add --no-ssh-pty option for Dropbear compatibility and other issues.

Dropbearで使えるようになるオプションが増えているようです.
DropbearはOpenSSHに比べて大分小さなsshdです.組み込みとかで使われているのを見ます.でも機能が物足りないなと思うことも.

mosh + Dropbearの組み合わせを試してみました.

試したのはこんな感じの環境です.

Host : Raspbian jessie(Raspberry Pi 2B)
Client : Debian sid amd64

dropbearの準備

HostにDropbearをパッケージで導入します

$ sudo apt install dropbear

dropbearのhost鍵を用意

$ mkdir /tmp/dropbear
$ dropbearkey -t ecdsa -s 521 -f /tmp/dropbear/dropbear_ecdsa_host_key
  • -t 鍵種類
  • -s 鍵長
  • -f 鍵ファイル

接続時に解りやすいようにバナーファイル作成

$ banner dropbear > /tmp/dropbear/banner

Dropbearを2222番ポートで起動

$ dropbear -r /tmp/dropbear/dropbear_ecdsa_host_key -p 2222 -b /tmp/dropbear/banner -E
  • -r host鍵を指定
  • -p sshポート番号
  • -b バナーファイル
  • -E 標準エラー出力にメッセージ出力

Dropbearにssh接続できるか確認

$ ssh pi@192.168.2.200 -i ~/.ssh/id_ecdsa -p 2222
Host key fingerprint is SHA256:G3u9pP4ZrkZ2kWs9e+ly9MkEtnO0f4ebvkBS0ObGJQQ
+---[ECDSA 521]---+
|          E+.    |
|           .+ .  |
|           +.+   |
|           .*o . |
|        S ..o++ .|
|         +o++oo= |
|        oo.o= *+=|
|         ..+ *o**|
|         o+o=.O=o|
+----[SHA256]-----+

 #####   #####    ####   #####   #####   ######    ##    #####
 #    #  #    #  #    #  #    #  #    #  #        #  #   #    #
 #    #  #    #  #    #  #    #  #####   #####   #    #  #    #
 #    #  #####   #    #  #####   #    #  #       ######  #####
 #    #  #   #   #    #  #       #    #  #       #    #  #   #
 #####   #    #   ####   #       #####   ######  #    #  #    #

Authenticated to 192.168.2.200 ([192.168.2.200]:2222).

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
pi@raspberrypi:~ $ 

mosh 1.3.0の準備

server側はsourceからbuild

$ sudo apt-get build-dep mosh
$ wget https://mosh.org/mosh-1.3.0.tar.gz
$ sha256sum mosh-1.3.0.tar.gz
320e12f461e55d71566597976bd9440ba6c5265fa68fbf614c6f1c8401f93376  mosh-1.3.0.tar.gz

※hashとgpg署名は以下のメールに,鍵は https://mosh.org/ の一番下にある.

sourceを展開してbuild

$ tar tvf mosh-1.3.0.tar.gz
$ tar xf mosh-1.3.0.tar.gz
$ ./configure --prefix=${HOME}/usr/local
$ make
$ install

host側はDebian sid amd64のパッケージを利用した

$ sudo apt install mosh
$ dpkg-query -W mosh
mosh    1.3.0-1

ということでホスト側はこんな状態に

  • OpenSSH : 22番ポート
  • Dropbear : 2222番ポート
  • mosh 1.2.4a-1+b2(pkg) : /usr/bin/mosh-server
  • mosh 1.3.0 : ${HOME}/usr/local/bin/mosh-server

この状態でDropbearとmosh 1.3.0を利用するにはこんな感じ

$ mosh pi@192.168.2.200 --ssh="ssh -p 2222" --server='${HOME}'/usr/local/bin/mosh-server

でも実際に繋ごうとするとエラーになってしまう.

接続元のmoshではこんなエラー

/usr/bin/mosh: Did not find mosh server startup message. (Have you installed mosh on your server?)

接続先のDropbearではこんなエラー

[20390] Mar 28 06:37:20 Child connection from 192.168.2.205:32888
[20390] Mar 28 06:37:21 Pubkey auth attempt with unknown algo for 'pi' from 192.168.2.205:32888
[20390] Mar 28 06:37:21 Pubkey auth succeeded for 'pi' with key md5 0b:fb:21:45:d6:a0:7d:57:02:24:9b:d3:ed:c7:c6:23 from 192.168.2.205:32888
[20391] Mar 28 06:37:21 ioctl(TIOCSCTTY): Input/output error
[20391] Mar 28 06:37:21 /dev/pts/1: No such file or directory
[20391] Mar 28 06:37:21 open /dev/tty failed - could not set controlling tty: No such device or address
[20390] Mar 28 06:37:21 Exit (pi): Disconnect received

ということで,mosh 1.3.0で入った--no-ssh-ptyを付けてみます.

$ mosh pi@192.168.2.200 --ssh="ssh -p 2222" --server='${HOME}'/usr/local/bin/mosh-server --no-ssh-pty

asciicast

うまく繋がりました.
試しに回線を切断して再接続すると自動的に繋がるのも確認 ☺

--no-ssh-ptyを~/.ssh/configとかに書いとけるといいんですけどね.今のところ毎回指定するしかなさそう?

]]>
https://matoken.org/blog/2017/03/28/try-dropbear-sshd-with-mosh-1-3-0/feed/ 0