Open4

M1 MBP + ubuntu with multipass

mitk232mitk232

multipassを使ってubuntuを動かす

  • install with homebrew
    • 指定しなければCPU 1コア, メモリ 1GB, ディスク 5GB
▶ brew install multipass
▶ multipass version
multipass   1.8.1+mac
multipassd  1.8.1+mac
  • LTS (20.04) のubuntuを起動
▶ multipass launch --name ubuntu20
Launched: ubuntu20

▶ multipass ls
Name                    State             IPv4             Image
ubuntu20                Running           192.168.64.2     Ubuntu 20.04 LTS

# インスタンスにコマンドを実行
▶ multipass exec ubuntu20 -- echo "Hello, World\!"
Hello, World!

# シェルにログイン
▶ multipass shell ubuntu20
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-99-generic aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Mar  2 15:17:51 JST 2022

  System load:  0.01              Processes:               95
  Usage of /:   26.6% of 4.68GB   Users logged in:         0
  Memory usage: 19%               IPv4 address for enp0s1: 192.168.64.2
  Swap usage:   0%


0 updates can be applied immediately.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Wed Mar  2 15:12:06 2022 from 192.168.64.1
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@ubuntu20:~$ echo $HOME
/home/ubuntu
ubuntu@ubuntu20:~$ ls /
bin  boot  dev  etc  home  lib  lost+found  media  mnt  opt  proc  root  run  sbin  snap  srv  sys  tmp  usr  var
ubuntu@ubuntu20:~$ echo $SHELL
/bin/bash
ubuntu@ubuntu20:~$ exit
logout
  • ubuntuユーザのパスワードを設定
sudo passwd ubuntu
mitk232mitk232

host (mac) からmultipass上のubuntuへssh接続

# multipassdに隠蔽されているssh-keyをコピペsudo cp /var/root/Library/Application\ Support/multipassd/ssh-keys/id_rsa ~/.ssh/id_multipass_rsa
Password:

# 権限をユーザに変更sudo chown `id -un` ~/.ssh/id_multipass_rsa

# 秘密鍵を指定してssh接続ssh -i ~/.ssh/id_multipass_rsa ubuntu@[IPv4]
The authenticity of host '192.168.64.2 (192.168.64.2)' can't be established.
ECDSA key fingerprint is SHA256:O+/pSo2n5tpXX8GKdr0Kkz8ptQqplQz3LMfD3vRi/Z4.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.64.2' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-99-generic aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Mar  2 15:25:00 JST 2022

  System load:  0.1               Processes:               97
  Usage of /:   26.6% of 4.68GB   Users logged in:         0
  Memory usage: 19%               IPv4 address for enp0s1: 192.168.64.2
  Swap usage:   0%


0 updates can be applied immediately.


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

Last login: Wed Mar  2 15:17:52 2022 from 192.168.64.1
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@ubuntu20:~$ exit
logout
Connection to 192.168.64.2 closed.

上で接続が確認できたため、~/.ssh/configに接続設定を追記

# ~/.ssh/config
## multipass ubuntu
Host ubuntu20
    HostName [IPv4]
    IdentityFile ~/.ssh/id_multipass_rsa
    User ubuntu