0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Multipass] macOSのzsh/VSCodeからUbuntuVMインスタンスにSSH接続する

Last updated at Posted at 2024-02-24

My Environment

Chip: Apple M3 Max
Memory: 64GB
macOS: Sonoma 14.2.1

前回の記事 (Multipass&Ubuntuについてはこちら)

Procedure

  • 以下のルールで表記します

    • %: macOSのzsh上でのコマンド操作
    • $: Ubuntuのbash上でのコマンド操作
% ssh-keygen -t ed25519 -C "<your_email_address@example.com>"
  • 保存場所はデフォルト(~/.ssh/id_ed25519, ~/.ssh/id_ed25519.pub)でOK (Enter)
  • パスワードを作成 → 再入力
% multipass ls
Name                    State             IPv4             Image
foo                     Running           192.168.64.5     Ubuntu 20.04 LTS
  • IPv4 (e.g. 192.168.64.5) を確認
Host foo
    HostName 192.168.64.5
    Port 22
    IdentityFile ~/.ssh/id_ed25519
    User ubuntu
  • 上の内容をmacOSの~/.ssh/configに記述
% pbcopy < ~/.ssh/id_ed25519.pub
  • 公開鍵をコピー
% multipass shell foo
  • Ubuntuのbashにログイン
$ echo "<paste_here>" >> ~/.ssh/authorized_key
  • Ubuntuの~/.ssh/authorized_keyに追記(ペースト)
$ exit
% multipass start foo
  • 注意: このUbuntuの再起動操作が重要

% ssh foo
  • zshからSSH接続をしてみる

    • 初回はyesの入力を求められる
    • パスワードを入力

  • VSCodeからSSH接続をしてみる

    • VSCodeで Remote - SSH をインストール
    • 画面左下のボタンをクリック
    • Connect to Host ... を選択
    • foo を選択
    • 初回はContinueの選択を求められる
    • 遷移先のVSCodeウィンドウでパスワードを入力

image.png

References

  • How to connect to Multipass via SSH (with VSCode):

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?