複数PCへのSSH接続を自動化：Zellijでターミナル作業を効率化

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2734306/fa0fbe38-02d3-4a02-9c45-cba1474c59a3.png)

# はじめに

複数台のロボットの開発を行う際、SSH接続作業が大きな負担になります。「ロボット1に接続、次のターミナルを開いて、ロボット2に接続...」という単調な作業の繰り返しは、開発中、非常に煩わしいものです。楽に開発できないかなぁといろいろツールを探していたところ、ターミナルのレイアウトを保存し、起動時に各ペインで自動的にコマンドを実行できることが可能な「[Zellij](https://zellij.dev/)」があると友達から紹介されました。ZellijはRust製のターミナルマルチプレクサで、画面分割やタブ管理の基本機能に加え、強力なレイアウト定義機能を備えています。そのため、接続コマンドを一度レイアウトファイルに定義するだけで、以降はたった一つのコマンドで全PCへの接続が完了します。ターミナルの`bashrc`がペインごとにできるというイメージです。また、Zellijは、コマンドが画面上表示されているためコマンドを覚えずとも雰囲気で操作が可能です。これが非常に便利で、ターミナル作業を効率化できます！皆さんもZellijを使って、煩わしい作業から開放されましょう！

※記事内にあるレイアウトファイルは以下のレポジトリにあります。
https://github.com/koki3141/zellij


# Zellijのインストール

- Ubuntu 22.04（WSL）

  ```shell
  curl -L -O https://github.com/zellij-org/zellij/releases/download/v0.42.2/zellij-x86_64-unknown-linux-musl.tar.gz
  sudo tar zxf zellij-x86_64-unknown-linux-musl.tar.gz -C /usr/local/bin
  ```

  ※最新バージョンは[公式リリースページ](https://github.com/zellij-org/zellij/releases)で確認してください。
- [Mac](https://github.com/zellij-org/zellij/blob/main/docs/THIRD_PARTY_INSTALL.md#macos)

  ```shell
  brew install zellij
  ```


インストール後、以下のコマンドで起動できます。

```shell
zellij
```

![https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/e6e4685e-da17-4ac9-a4d5-204ea0f86aba/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2L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RoWMoWOwtTyagLbRwyCWzpui%2FdfN2CzL6H4qJdNblq%2FNAcZQDHipXbkU6ytrYqvJE%2B4kYSFOke%2FdrcJdPy2ukNwyowIiT8NFGZl2axOpkQCSrgcNMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=d186ba3e5e160f5135fde782abb6b49c5c13995c5ba6560631acdda28ca4b639&X-Amz-SignedHeaders=host&x-id=GetObject](https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/e6e4685e-da17-4ac9-a4d5-204ea0f86aba/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TYDCZN6H%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113325Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJHMEUCIBVSF0uJr%2BSOSPYy6Vaul3G2ksSnmg6DgkNq%2Fig3f5RTAiEA33rOcyXLSIi0bZ7mLjeHk7Baa7EfUjD%2Bl%2B3AE86LDjcq%2FwMIXBAAGgw2Mzc0MjMxODM4MDUiDKsPALiNGQSaYtLJ1SrcA98ZgPIniEXT8w1RbF2ctS3fbc9XxdTkU%2F%2FGvL7bw2mktG0xHji9Xx3Q34Jq1mrkc8rX09BqFDTQmY49fSmB2Y14P%2FBcc%2BcXw7AqrOVp%2BgC7bYVco2qNJtrpNaO9CiOXoi6MZsjwUYx6eGjXNM2XCPkKxZwH2eFe4cJa%2FYMD1jurBsk3z3pYbXDFzgCojL%2B5DQFDHtd51U7Uo83gmfFEkH6w5v%2F4wWdjoNRZRL4yQOwTRIWUnhjeKeWj59cTM6OGzI32R3SN5DvC%2BoZbK0rPYcj%2FgkxjK%2BAmbn3IOW2mh2gQW6YtIE1TOIwAnnR%2FC%2BHdzYVL1EfzJiHf%2FtBKIW6vazxuCD5wZs4H%2BtIHEKUO0aZM1K0ee0hITUP4D6IYpgvOgItWCN19qkVVEz2TqJ6u%2BvtNGWLznEPk0K%2BaJpCUm%2FQ6XJVrRPdOcXiZiEqXhTo8TBfMIIwtIsmnENjzdET08pKJuly6nyb7Uwon1z6eQq7teOQWHtccX1VytBjFmpYQwtc1Dj7B7BS40xICn6KwVvO6d3FfLqJ3G3hzZ8efYfasovh32KiUV8a%2Fs60FnWqqKeIqs70GQUzRW%2Bss647tAi9nX5vb27ApuOeZFDFOAyPKLYm8xrusxTYGq4eAMLrGg8AGOqUBnUQbQkgHPe1xZO7%2Fmeptrk5ilPzY%2Bg36%2BWMRwugX5hE%2BPaXUI5mPRoWMoWOwtTyagLbRwyCWzpui%2FdfN2CzL6H4qJdNblq%2FNAcZQDHipXbkU6ytrYqvJE%2B4kYSFOke%2FdrcJdPy2ukNwyowIiT8NFGZl2axOpkQCSrgcNMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=d186ba3e5e160f5135fde782abb6b49c5c13995c5ba6560631acdda28ca4b639&X-Amz-SignedHeaders=host&x-id=GetObject)
※WSLでの実行結果です。
起動できたら、インストール完了です！

# Zellijの基本操作

次に、軽くZellij使い方について解説します。Zellijのユニークな特徴は、画面下部のステータスバーにコマンドリストが表示されることです。これにより、コマンドを完全に覚えなくても直感的に操作できます。

## 新しいペインを開くの動作例

新しいペインを開く動作を例に、Zellijの操作を説明します。
1. Zellijの起動
   Zellijを立ち上げてください。

   ```shell
   zellij
   ```

   ![https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/e6e4685e-da17-4ac9-a4d5-204ea0f86aba/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB4662KGXX7X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ttIzDURepZPwPLBO96%2FT9bi2mjs8JCkizGDUUvKcs072cRZTGrZ%2Fh%2BXWIaqlZ1o%2FB94EZl1j00Tecs0sgoho1knXpq3bbeI%2BM8CDdvi5X%2BtRyMdnggpbNzNsmQ1imKqOIGx9wJB5982grvKfT7O&X-Amz-Signature=49a0f396ee819719361d6effab348b1c92f3c936916a0e2f156984df870a3cca&X-Amz-SignedHeaders=host&x-id=GetObject](https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/e6e4685e-da17-4ac9-a4d5-204ea0f86aba/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB4662KGXX7XZ%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113328Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJGMEQCIGVS6pCfwOGqMRcMmrU7W4t3Z38lI71IQG%2BOtdZ4KgPtAiB75auu7zDrqRoSwMeSalyr5p11o77SJ0iDqiH6BnKk%2Fyr%2FAwhcEAAaDDYzNzQyMzE4MzgwNSIMgnHpdqOaEOJ5xe48KtwDNKX1oHuiLAjdNlzpYu92oCaYj77EcWB76GiSSW%2Bz3xwdFixx%2BHFOj6464vM6pOrOGFA5iQq53kbHj2DNKzL3ojSaqBiLnpXALWyYbfVB8NLO5UXXmn9%2FmP7MxameJpBpVmyVqaE2GWKM6R%2FM8gDD6iTH1Xbza9z33ZiWaS3egUmi5dAJLjwk6de1PwjpPIYtwFxwxVDp%2BCnMy8fh7mpF6kv%2F90p9K%2FQ3IozO0hcYt1p4vzMd4TpKtG9PO5KdpnjVIoWF1QFxxhQa%2BJ85tTXnLWa0cMeL712c2HPIGvEaSEc5VauSP1pfo0XpiQlgVA%2BpA1svt5Hov22UCtkBh4WGRw7i4cFZc2eNR6kDIrKHivHpKjcxyHuxj8YL%2BBnPdDJ87czkxh7lBTUwMmDI2SCCwtFnWt1Pzv7hPRCBVTaH8kOA%2BJb1UI0uoD0YZDs733%2F1UPBq%2F%2Bf1tLwwf%2Fk4qteRMTzhJFzqkWtjimysJ7n90ZF7tg8hXawqVgfzz1j6nRoS01vowlKN5GBSBxWlfLqUEhLXLCJuJHuxhs8wE7L%2BX%2Fg%2FpME3PHnMuM0A9ko1msp13P2Rrq8cLbVGBeQcQUkrcaPpSSClsJfCbhsCmKisN08vVCoj2oxkXsVLNaUwu8aDwAY6pgGHCzIjlzT%2BenWwx32jfSVtq0zdNkFWPa9G%2BrIZMwTTxqM%2F2eTkmIeA4VN6Z3LXLMmjtGxPwu5gnttIzDURepZPwPLBO96%2FT9bi2mjs8JCkizGDUUvKcs072cRZTGrZ%2Fh%2BXWIaqlZ1o%2FB94EZl1j00Tecs0sgoho1knXpq3bbeI%2BM8CDdvi5X%2BtRyMdnggpbNzNsmQ1imKqOIGx9wJB5982grvKfT7O&X-Amz-Signature=49a0f396ee819719361d6effab348b1c92f3c936916a0e2f156984df870a3cca&X-Amz-SignedHeaders=host&x-id=GetObject)
2. ペインモードに入る
   ステータスバーのPANEの`ctrl+p`を押し、paneを操作するモードに入ります。
   ![https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/444d44d9-4667-4b37-a511-3ca14deb592f/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466RUBFYUE5%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113330Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENT%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJHMEUCIQDhhSJh88nZIFgDS4JLWVaEp9afZDeeMx3%2BBxpraI24iwIgEBSVovEPlp0Kaygnh5IBZrqcQv4YQjv5JwfHAENJKygq%2FwMIXBAAGgw2Mzc0MjMxODM4MDUiDJ%2FFDDvpFPzkhSMHSyrcAyVP0AMvWhpwYj8V%2B9gZb%2FGtVrH0QXaZcXfYNe63jIW6KkFE0uOl11aIBkeWGGZxfyUgu8vOWNJvpmNi6CHxqrZFHOscpijQScPZHBsqgt%2FF06llgUMKAUSUjIL14SCM3O59nU9jC%2BBDvpqIpHpRFmkMeCWKI8e533vMBZs94XVKfahoWsr3rTtfzVVPRGdHsC3lefE3%2B3V%2B8I68R4FdNVQzWGdRRSfOkuxL33kpXELaZqXKD%2FUl5PBJQWh2awHqgrRDzgz3p5rWU8aHuB4K4cANiDKoO9xPj7Es9OfnX9g2VWR3ZzerGcGTcedFg6xBFzzBubqtrA9zbtdnwhLFOoj00yNFr%2BsfbEOORaHsfKmVmQ%2Fd%2FHTkYGawFvJhyp4B7WDlIwKaoiYluuXm%2FARmKzzrlj06WLRkJfWqmbiKYlp160iir48IRNyMEjUs37rXRvni6FYT%2Bf4yu9cAPuAbMYxuGJ4%2BJ0csmGreAUdl%2BzJA3v4WpgH5PMY3r1csqZNWrPtmed1xaz6xW96d8xLceJayqw3E6B3%2F5xcuaxW0sP%2FbHOD5ll04HV97NS90JtWdSk8uCKUdDVZWQCdqBroyU8jtZKMSbtOykXHmL91s3NY22CrGAwMydMNVtxSYMOvGg8AGOqUBXodoetqtP2OImA2P%2BjVH40iuzhpSqmHPbt5TZOM2ii%2BMAA2AZqTXC724oMQNXth3Qigo1LCGPbZ3oBDoI6MWspgTQg9bvP8G0lS5WzYJlSsPXsS0KgU%2BstRgGcxWgnga5gCVoyJShVYBAm6jS63K2gfPM1atWwkzdovSfjZvJgY4jHG7qX57rYHgd9GghS%2BBZr0QeUZuan7tkbuzr%2BJVRrbqBv8B&X-Amz-Signature=113bebf5135cc57a533207054c43811710056c022bdd8666029e201ee9f697f2&X-Amz-SignedHeaders=host&x-id=GetObject](https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/444d44d9-4667-4b37-a511-3ca14deb592f/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466RUBFYUE5%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113330Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENT%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJHMEUCIQDhhSJh88nZIFgDS4JLWVaEp9afZDeeMx3%2BBxpraI24iwIgEBSVovEPlp0Kaygnh5IBZrqcQv4YQjv5JwfHAENJKygq%2FwMIXBAAGgw2Mzc0MjMxODM4MDUiDJ%2FFDDvpFPzkhSMHSyrcAyVP0AMvWhpwYj8V%2B9gZb%2FGtVrH0QXaZcXfYNe63jIW6KkFE0uOl11aIBkeWGGZxfyUgu8vOWNJvpmNi6CHxqrZFHOscpijQScPZHBsqgt%2FF06llgUMKAUSUjIL14SCM3O59nU9jC%2BBDvpqIpHpRFmkMeCWKI8e533vMBZs94XVKfahoWsr3rTtfzVVPRGdHsC3lefE3%2B3V%2B8I68R4FdNVQzWGdRRSfOkuxL33kpXELaZqXKD%2FUl5PBJQWh2awHqgrRDzgz3p5rWU8aHuB4K4cANiDKoO9xPj7Es9OfnX9g2VWR3ZzerGcGTcedFg6xBFzzBubqtrA9zbtdnwhLFOoj00yNFr%2BsfbEOORaHsfKmVmQ%2Fd%2FHTkYGawFvJhyp4B7WDlIwKaoiYluuXm%2FARmKzzrlj06WLRkJfWqmbiKYlp160iir48IRNyMEjUs37rXRvni6FYT%2Bf4yu9cAPuAbMYxuGJ4%2BJ0csmGreAUdl%2BzJA3v4WpgH5PMY3r1csqZNWrPtmed1xaz6xW96d8xLceJayqw3E6B3%2F5xcuaxW0sP%2FbHOD5ll04HV97NS90JtWdSk8uCKUdDVZWQCdqBroyU8jtZKMSbtOykXHmL91s3NY22CrGAwMydMNVtxSYMOvGg8AGOqUBXodoetqtP2OImA2P%2BjVH40iuzhpSqmHPbt5TZOM2ii%2BMAA2AZqTXC724oMQNXth3Qigo1LCGPbZ3oBDoI6MWspgTQg9bvP8G0lS5WzYJlSsPXsS0KgU%2BstRgGcxWgnga5gCVoyJShVYBAm6jS63K2gfPM1atWwkzdovSfjZvJgY4jHG7qX57rYHgd9GghS%2BBZr0QeUZuan7tkbuzr%2BJVRrbqBv8B&X-Amz-Signature=113bebf5135cc57a533207054c43811710056c022bdd8666029e201ee9f697f2&X-Amz-SignedHeaders=host&x-id=GetObject)
   ステータスバーが変化し、paneを操作するモードに入ったことがわかります。
3. 新しいペインを開く
   そして、Newの`n` を押すと、新しくpeneを開くことができます。
   ![https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/dcbbabff-9528-4d4c-bfc8-5bcbf7d0d862/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466VOOTO37U%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113330Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJIMEYCIQCUuzATw10mdaot%2BWRvZOM9cl7MGa7lWDmFjBuL%2BTGI3wIhAKQGXSlcMoUzuWUrwuuYLgCpOuTXKuXynzYcKssFuF3iKv8DCFwQABoMNjM3NDIzMTgzODA1IgwjtiLVuV87eKvJXFQq3ANssRUUCjic9xfswFU71xMO73gl1hIdyiQ9F%2B0jFikUA4wl1oZCJ8fEOWvZ%2FneRH5Wc3YloYmE2zr1M4pFLd7QxzCtj4JLydxP7sBfftr9AxjknWTIBmHH3NOKt52%2FakAjmWkMxfDHYbj%2F7Iyl%2BOywmwkhlB%2B7zpOzGAYIxGRA7hD0axehqr0w%2FroNHkdzsbcjjlSkA9QtNMTYr1EjVtSg011vj7lV0piVqztytyFBuTarVwNzvRZhr70QoBornr72CvOITQ9azEoFHoDENELZ3VgZvcdVLJ6m6p4hGFQfCAgKcPF6XegqQ52rs1iGNtI4iRhyX8W5kbkpeDvZIDWy4kIP87FxirjGWqz657BTQ%2BJlPbB7ed6QEbHeQjvRF8UGHwqYWHbixS3I8bXlWcltCWPwx24cn5UYeJkXUX6V5zx%2FLSm8cu08vTRvtYUKL%2Fnv6HFkfygRGmWOuakN%2BQ9ycXAHL2leA8e5%2BsOpngI0AUQS6lGV%2B%2BQI7Dsy46rBucug39kV%2BhB6HfR7jipmEhhHelZVCkFXMxKgpIn7md2Gun8v9w5rii66HO0oBq%2BYbM0t4Sz6ANdrZYsnTFyL2tis0dZMWb%2BfGrRLQNOXMbftlUZ1zMpqMt%2FSoM1XomDC7xoPABjqkAUzcQr7mQA6X3yL8CyzuhnxsL09Hec8tZl4XBI2l6IkWYd5zorncCo8z80B9bXH2Wz7Q2KtkcCY%2FMB1lfhpxU6iemJyhTVQxP15oojQdaZg4pSxQ8QZAZYszv2xkIPxcuzHqJEa5ILP%2B4Eamop05p1nsnTPEqxrQbuxbU5%2F3oVmAbPb66mNwBrLvav6DuFeuzoTXALP5S246N%2FCMEYNPq6FZcS2I&X-Amz-Signature=9d2e90bab7cc23a4ccbde8ba6110d466ef0ac53854b7d568a53f29608a9399bc&X-Amz-SignedHeaders=host&x-id=GetObject](https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/dcbbabff-9528-4d4c-bfc8-5bcbf7d0d862/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466VOOTO37U%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113330Z&X-Amz-Expires=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U5%2F3oVmAbPb66mNwBrLvav6DuFeuzoTXALP5S246N%2FCMEYNPq6FZcS2I&X-Amz-Signature=9d2e90bab7cc23a4ccbde8ba6110d466ef0ac53854b7d568a53f29608a9399bc&X-Amz-SignedHeaders=host&x-id=GetObject)

このように、下のステータスバーで、どのような状況なのか、どのようなコマンドがあるのか可視化されているので、ドキュメントを見ず、なんとなくで操作できます。
Zellijを終了したい場合は、下のステータスバーの一番右にある「QUIT」のq、つまり`ctrl-q` でできます。

# **複数PCへのSSH接続を自動化する**

雰囲気、Zellijについて理解したところで、本題の起動時に複数のペインごとにSSH接続する方法について説明していきます。Zellijは、[レイアウト](https://zellij.dev/documentation/layouts)にペインやタブを定義することにより、起動時にSSH接続を自動化することが可能になります。これを用いて、複数のペインごとにSSH接続のコマンドを実行するという仕組みを作ります。

### **レイアウトファイルの基本構造**

Zellij起動時にレイアウト定義を読み込ませることで、ターミナルの分割とコマンド実行を自動化できます。基本的なレイアウトファイルは以下のような構造になります
- panes_command.kdl

  ```shell
  layout {
      // tabとstatusバーの表示設定
      default_tab_template {
          pane size=1 borderless=true {
              plugin location="zellij:tab-bar"
          }
          children
          pane size=2 borderless=true {
              plugin location="zellij:status-bar"
          }
      }

      // 複数のpane設定
      tab {
          // pane設定
          pane name="pane1" command="bash" {
              // 実行コマンドの設定
              args "-c" "echo pane1 ssh user@ip_address; bash"
          }
          pane name="pane2" command="bash" {
              // 実行コマンドの設定
              args "-c" "echo pane2 ssh user@ip_address; bash"
          }
      }
  }
  ```

レイアウトファイルを作成し、以下のコマンドを実行してください。

```shell
zellij -l panes_command.kdl
```

![https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/6a5640e0-cf53-49a5-903b-4ccd26949455/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TYDCZN6H%2F20250417%2Fus-west-2%2Fs3%2Faws4_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Nblq%2FNAcZQDHipXbkU6ytrYqvJE%2B4kYSFOke%2FdrcJdPy2ukNwyowIiT8NFGZl2axOpkQCSrgcNMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=e0d040656cb998b43d538a0b1e2e16bd20e6001877fecf443b4d1403fa45ff16&X-Amz-SignedHeaders=host&x-id=GetObject](https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/6a5640e0-cf53-49a5-903b-4ccd26949455/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TYDCZN6H%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113325Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJHMEUCIBVSF0uJr%2BSOSPYy6Vaul3G2ksSnmg6DgkNq%2Fig3f5RTAiEA33rOcyXLSIi0bZ7mLjeHk7Baa7EfUjD%2Bl%2B3AE86LDjcq%2FwMIXBAAGgw2Mzc0MjMxODM4MDUiDKsPALiNGQSaYtLJ1SrcA98ZgPIniEXT8w1RbF2ctS3fbc9XxdTkU%2F%2FGvL7bw2mktG0xHji9Xx3Q34Jq1mrkc8rX09BqFDTQmY49fSmB2Y14P%2FBcc%2BcXw7AqrOVp%2BgC7bYVco2qNJtrpNaO9CiOXoi6MZsjwUYx6eGjXNM2XCPkKxZwH2eFe4cJa%2FYMD1jurBsk3z3pYbXDFzgCojL%2B5DQFDHtd51U7Uo83gmfFEkH6w5v%2F4wWdjoNRZRL4yQOwTRIWUnhjeKeWj59cTM6OGzI32R3SN5DvC%2BoZbK0rPYcj%2FgkxjK%2BAmbn3IOW2mh2gQW6YtIE1TOIwAnnR%2FC%2BHdzYVL1EfzJiHf%2FtBKIW6vazxuCD5wZs4H%2BtIHEKUO0aZM1K0ee0hITUP4D6IYpgvOgItWCN19qkVVEz2TqJ6u%2BvtNGWLznEPk0K%2BaJpCUm%2FQ6XJVrRPdOcXiZiEqXhTo8TBfMIIwtIsmnENjzdET08pKJuly6nyb7Uwon1z6eQq7teOQWHtccX1VytBjFmpYQwtc1Dj7B7BS40xICn6KwVvO6d3FfLqJ3G3hzZ8efYfasovh32KiUV8a%2Fs60FnWqqKeIqs70GQUzRW%2Bss647tAi9nX5vb27ApuOeZFDFOAyPKLYm8xrusxTYGq4eAMLrGg8AGOqUBnUQbQkgHPe1xZO7%2Fmeptrk5ilPzY%2Bg36%2BWMRwugX5hE%2BPaXUI5mPRoWMoWOwtTyagLbRwyCWzpui%2FdfN2CzL6H4qJdNblq%2FNAcZQDHipXbkU6ytrYqvJE%2B4kYSFOke%2FdrcJdPy2ukNwyowIiT8NFGZl2axOpkQCSrgcNMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=e0d040656cb998b43d538a0b1e2e16bd20e6001877fecf443b4d1403fa45ff16&X-Amz-SignedHeaders=host&x-id=GetObject)
縦にペインが並び、上がpane1、下がpane2となっています。また、それぞれの`echo` の結果が表示されていることが確認できます。

## **SSH接続用レイアウトの作成**

実際にSSH接続するレイアウトを作成するには、以下のようなファイルを作成します。`user@ip_address`を実際の接続情報に置き換えてください。
- robots_ssh.kdl

  ```shell
  layout {
      // tabとstatusバーの表示設定
      default_tab_template {
          pane size=1 borderless=true {
              plugin location="zellij:tab-bar"
          }
          children
          pane size=2 borderless=true {
              plugin location="zellij:status-bar"
          }
      }

      // 複数のpane設定
      tab {
          // pane設定
          pane name="pane1" command="bash" {
              // 実行コマンドの設定
              args "-c" "ssh user@ip_address; bash"
          }
          pane name="pane2" command="bash" {
              // 実行コマンドの設定
              args "-c" "ssh user@ip_address; bash"
          }
      }
  }
  ```

接続を設定したら、このファイルを `robots_ssh.kdl` として保存し、以下のコマンドで実行します。

```shell
zellij -l robots_ssh.kdl
```

これにより、2つのペインが作成され、それぞれのペインで自動的にSSH接続コマンドが実行されます。
※SSH接続をパスワードなしで接続したい場合は[こちら](https://qiita.com/koki3141/items/5e59c4a3aa9d56408085#%E3%83%91%E3%82%B9%E3%83%AF%E3%83%BC%E3%83%89%E7%84%A1%E3%81%97%E3%81%A7%E6%8E%A5%E7%B6%9A%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95)の記事を参考にしてみてください。

## **自作レイアウトをデフォルトに設定**

レイアウトをデフォルトに設定するには：
1. Zellijの設定ディレクトリに `layouts` フォルダを作成

   ```shell
   mkdir -p ~/.config/zellij/layouts
   ```

2. 作成したレイアウトファイルを `default.kdl` として保存

   ```shell
   cp robots_ssh.kdl ~/.config/zellij/layouts/default.kdl
   ```

これにより、`zellij` コマンドを実行するだけで自動的に設定したレイアウトが適用されます。

# **レイアウト設定のバリエーション**

ペインとタブのレイアウトの設定に関するいくつかの例を上げています。

### **横に2つのペインを並べる**

- vertical2.kdl

  ```shell
  layout {
  	default_tab_template {
  	      pane size=1 borderless=true {
  	          plugin location="zellij:tab-bar"
  		      }
  	      children
  	      pane size=2 borderless=true {
  	          plugin location="zellij:status-bar"
  	      }
  	  }
  	  tab {
  		    pane split_direction="vertical" {
  		        pane name="left"
  		        pane name="right"
  		    }
      }
  }
  ```

レイアウトファイルを作成し、以下のコマンドを実行してください。

```shell
zellij -l vertical2.kdl
```


![https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/26eaa024-314a-4f92-8c83-4ccd21616d95/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TYDCZN6H%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113325Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENP%2F%2F%2F%2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NMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=8d23ac901c00ed8cf77d44ba9277af7b370179dd6d02a38744e93d19da8a8f94&X-Amz-SignedHeaders=host&x-id=GetObject](https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/26eaa024-314a-4f92-8c83-4ccd21616d95/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TYDCZN6H%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113325Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJHMEUCIBVSF0uJr%2BSOSPYy6Vaul3G2ksSnmg6DgkNq%2Fig3f5RTAiEA33rOcyXLSIi0bZ7mLjeHk7Baa7EfUjD%2Bl%2B3AE86LDjcq%2FwMIXBAAGgw2Mzc0MjMxODM4MDUiDKsPALiNGQSaYtLJ1SrcA98ZgPIniEXT8w1RbF2ctS3fbc9XxdTkU%2F%2FGvL7bw2mktG0xHji9Xx3Q34Jq1mrkc8rX09BqFDTQmY49fSmB2Y14P%2FBcc%2BcXw7AqrOVp%2BgC7bYVco2qNJtrpNaO9CiOXoi6MZsjwUYx6eGjXNM2XCPkKxZwH2eFe4cJa%2FYMD1jurBsk3z3pYbXDFzgCojL%2B5DQFDHtd51U7Uo83gmfFEkH6w5v%2F4wWdjoNRZRL4yQOwTRIWUnhjeKeWj59cTM6OGzI32R3SN5DvC%2BoZbK0rPYcj%2FgkxjK%2BAmbn3IOW2mh2gQW6YtIE1TOIwAnnR%2FC%2BHdzYVL1EfzJiHf%2FtBKIW6vazxuCD5wZs4H%2BtIHEKUO0aZM1K0ee0hITUP4D6IYpgvOgItWCN19qkVVEz2TqJ6u%2BvtNGWLznEPk0K%2BaJpCUm%2FQ6XJVrRPdOcXiZiEqXhTo8TBfMIIwtIsmnENjzdET08pKJuly6nyb7Uwon1z6eQq7teOQWHtccX1VytBjFmpYQwtc1Dj7B7BS40xICn6KwVvO6d3FfLqJ3G3hzZ8efYfasovh32KiUV8a%2Fs60FnWqqKeIqs70GQUzRW%2Bss647tAi9nX5vb27ApuOeZFDFOAyPKLYm8xrusxTYGq4eAMLrGg8AGOqUBnUQbQkgHPe1xZO7%2Fmeptrk5ilPzY%2Bg36%2BWMRwugX5hE%2BPaXUI5mPRoWMoWOwtTyagLbRwyCWzpui%2FdfN2CzL6H4qJdNblq%2FNAcZQDHipXbkU6ytrYqvJE%2B4kYSFOke%2FdrcJdPy2ukNwyowIiT8NFGZl2axOpkQCSrgcNMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=8d23ac901c00ed8cf77d44ba9277af7b370179dd6d02a38744e93d19da8a8f94&X-Amz-SignedHeaders=host&x-id=GetObject)

### **縦に2つのペインを並べる**

- horizontal2.kdl

  ```shell
  layout {
  	default_tab_template {
  	      pane size=1 borderless=true {
  	          plugin location="zellij:tab-bar"
  	      }
  	      children
  	      pane size=2 borderless=true {
  	          plugin location="zellij:status-bar"
  	      }
  	  }
  	  tab {
  		    pane split_direction="horizontal" {
  		        pane name="upper"
  		        pane name="below"
  		    }
      }
  }
  ```

レイアウトファイルを作成し、以下のコマンドを実行してください。

```shell
zellij -l horizontal2.kdl
```

![https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/ee4f45ac-3c64-4498-9b0f-290833d55cc2/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TYDCZN6H%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113325Z&X-Amz-Expires=3600&X-Amz-Security-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JdPy2ukNwyowIiT8NFGZl2axOpkQCSrgcNMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=174830d202594f29c7ff354a5c2a158242f083c7cd7820bdfa721f73af77503f&X-Amz-SignedHeaders=host&x-id=GetObject](https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/ee4f45ac-3c64-4498-9b0f-290833d55cc2/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TYDCZN6H%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113325Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJHMEUCIBVSF0uJr%2BSOSPYy6Vaul3G2ksSnmg6DgkNq%2Fig3f5RTAiEA33rOcyXLSIi0bZ7mLjeHk7Baa7EfUjD%2Bl%2B3AE86LDjcq%2FwMIXBAAGgw2Mzc0MjMxODM4MDUiDKsPALiNGQSaYtLJ1SrcA98ZgPIniEXT8w1RbF2ctS3fbc9XxdTkU%2F%2FGvL7bw2mktG0xHji9Xx3Q34Jq1mrkc8rX09BqFDTQmY49fSmB2Y14P%2FBcc%2BcXw7AqrOVp%2BgC7bYVco2qNJtrpNaO9CiOXoi6MZsjwUYx6eGjXNM2XCPkKxZwH2eFe4cJa%2FYMD1jurBsk3z3pYbXDFzgCojL%2B5DQFDHtd51U7Uo83gmfFEkH6w5v%2F4wWdjoNRZRL4yQOwTRIWUnhjeKeWj59cTM6OGzI32R3SN5DvC%2BoZbK0rPYcj%2FgkxjK%2BAmbn3IOW2mh2gQW6YtIE1TOIwAnnR%2FC%2BHdzYVL1EfzJiHf%2FtBKIW6vazxuCD5wZs4H%2BtIHEKUO0aZM1K0ee0hITUP4D6IYpgvOgItWCN19qkVVEz2TqJ6u%2BvtNGWLznEPk0K%2BaJpCUm%2FQ6XJVrRPdOcXiZiEqXhTo8TBfMIIwtIsmnENjzdET08pKJuly6nyb7Uwon1z6eQq7teOQWHtccX1VytBjFmpYQwtc1Dj7B7BS40xICn6KwVvO6d3FfLqJ3G3hzZ8efYfasovh32KiUV8a%2Fs60FnWqqKeIqs70GQUzRW%2Bss647tAi9nX5vb27ApuOeZFDFOAyPKLYm8xrusxTYGq4eAMLrGg8AGOqUBnUQbQkgHPe1xZO7%2Fmeptrk5ilPzY%2Bg36%2BWMRwugX5hE%2BPaXUI5mPRoWMoWOwtTyagLbRwyCWzpui%2FdfN2CzL6H4qJdNblq%2FNAcZQDHipXbkU6ytrYqvJE%2B4kYSFOke%2FdrcJdPy2ukNwyowIiT8NFGZl2axOpkQCSrgcNMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=174830d202594f29c7ff354a5c2a158242f083c7cd7820bdfa721f73af77503f&X-Amz-SignedHeaders=host&x-id=GetObject)

## 2つのタブの設定

2つのtabを設定しており、名前をつけています。各タブは横に2つのペインが並ぶようにしています。また、tab1の名前のタブを`focus=true`でメインtabにしています。
- tab2.kdl

  ```shell
  layout {
      default_tab_template {
          pane size=1 borderless=true {
              plugin location="zellij:tab-bar"
          }
          children
          pane size=2 borderless=true {
              plugin location="zellij:status-bar"
          }
      }

      tab name="tab1" focus=true {
          pane split_direction="vertical" {
              pane name="tab1_pane_left"
              pane name="tab2_pane_right"
          }
      }

      tab name="tab2" {
          pane split_direction="vertical" {
              pane name="tab2_pane_left"
              pane name="tab2_pane_right"
          }
      }
  }
  ```

レイアウトファイルを作成し、以下のコマンドを実行してください。

```shell
zellij -l tab2.kdl
```

![https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/46fe82a8-7add-451e-bf2a-ada1b964f934/image.png?X-Amz-Algorithm=AWS4-HMAC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kgHPe1xZO7%2Fmeptrk5ilPzY%2Bg36%2BWMRwugX5hE%2BPaXUI5mPRoWMoWOwtTyagLbRwyCWzpui%2FdfN2CzL6H4qJdNblq%2FNAcZQDHipXbkU6ytrYqvJE%2B4kYSFOke%2FdrcJdPy2ukNwyowIiT8NFGZl2axOpkQCSrgcNMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=f71390217f2315398b12b7c7d74742a6940a93d2f4497c33bc7bda3d723cf40f&X-Amz-SignedHeaders=host&x-id=GetObject](https://prod-files-secure.s3.us-west-2.amazonaws.com/7d28f4ba-f640-4c31-bd4e-c94f39bde737/46fe82a8-7add-451e-bf2a-ada1b964f934/image.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TYDCZN6H%2F20250417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250417T113325Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjENP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJHMEUCIBVSF0uJr%2BSOSPYy6Vaul3G2ksSnmg6DgkNq%2Fig3f5RTAiEA33rOcyXLSIi0bZ7mLjeHk7Baa7EfUjD%2Bl%2B3AE86LDjcq%2FwMIXBAAGgw2Mzc0MjMxODM4MDUiDKsPALiNGQSaYtLJ1SrcA98ZgPIniEXT8w1RbF2ctS3fbc9XxdTkU%2F%2FGvL7bw2mktG0xHji9Xx3Q34Jq1mrkc8rX09BqFDTQmY49fSmB2Y14P%2FBcc%2BcXw7AqrOVp%2BgC7bYVco2qNJtrpNaO9CiOXoi6MZsjwUYx6eGjXNM2XCPkKxZwH2eFe4cJa%2FYMD1jurBsk3z3pYbXDFzgCojL%2B5DQFDHtd51U7Uo83gmfFEkH6w5v%2F4wWdjoNRZRL4yQOwTRIWUnhjeKeWj59cTM6OGzI32R3SN5DvC%2BoZbK0rPYcj%2FgkxjK%2BAmbn3IOW2mh2gQW6YtIE1TOIwAnnR%2FC%2BHdzYVL1EfzJiHf%2FtBKIW6vazxuCD5wZs4H%2BtIHEKUO0aZM1K0ee0hITUP4D6IYpgvOgItWCN19qkVVEz2TqJ6u%2BvtNGWLznEPk0K%2BaJpCUm%2FQ6XJVrRPdOcXiZiEqXhTo8TBfMIIwtIsmnENjzdET08pKJuly6nyb7Uwon1z6eQq7teOQWHtccX1VytBjFmpYQwtc1Dj7B7BS40xICn6KwVvO6d3FfLqJ3G3hzZ8efYfasovh32KiUV8a%2Fs60FnWqqKeIqs70GQUzRW%2Bss647tAi9nX5vb27ApuOeZFDFOAyPKLYm8xrusxTYGq4eAMLrGg8AGOqUBnUQbQkgHPe1xZO7%2Fmeptrk5ilPzY%2Bg36%2BWMRwugX5hE%2BPaXUI5mPRoWMoWOwtTyagLbRwyCWzpui%2FdfN2CzL6H4qJdNblq%2FNAcZQDHipXbkU6ytrYqvJE%2B4kYSFOke%2FdrcJdPy2ukNwyowIiT8NFGZl2axOpkQCSrgcNMv5MTAk1oUuutZccsILB4J1yS5g6RuoadxHB9z7OZN18rBFpknTyi9wC&X-Amz-Signature=f71390217f2315398b12b7c7d74742a6940a93d2f4497c33bc7bda3d723cf40f&X-Amz-SignedHeaders=host&x-id=GetObject)

## まとめ

Zellijのレイアウト機能を使うことで、一度設定すれば、複数PCへのSSH接続を自動化することができました。研究室に配属されてから、どうにか複数ロボットへのSSH接続の効率化しようとtmuxを使ったり、terminatorを使ったり、してきましたがやっと使いやすいツールを見つけました。同じような悩みを持っている方々のお役に立ててもらえればと思います！よき開発ライフを！

# 参考資料

[https://zellij.dev/documentation/layouts](https://zellij.dev/documentation/layouts)
[https://zenn.dev/5ei74r0/articles/zellij-for-beginners](https://zenn.dev/5ei74r0/articles/zellij-for-beginners)
[https://zellij.dev/tutorials/layouts/](https://zellij.dev/tutorials/layouts/)