tekitoumemo’s diary

思ったことを書くだけ。長文版Twitter

macでAzure CLI入れてApp Serviceにsshするまで

App ServiceはPaasなのでsshを使う意味はほとんどありませんが、検証する際にたまーに必要になったりします。Azure portalから簡易的なsshが使えるので、必要はないのですが、芸がないので一応やってみることにしました。

HomebrewでAzure Cliをインストール

brew update && brew install azure-cli

バージョン確認

az --version
azure-cli                         2.0.77

command-modules-nspkg              2.0.3
core                              2.0.77
nspkg                              3.0.4
telemetry                          1.0.4

Python location '/usr/local/Cellar/azure-cli/2.0.77/libexec/bin/python'
Extensions directory '/Users/saitouikuo/.azure/cliextensions'

Python (Darwin) 3.7.5 (default, Nov  1 2019, 02:16:23)
[Clang 11.0.0 (clang-1100.0.33.8)]

Legal docs and information: aka.ms/AzureCliLegal



Your CLI is up-to-date.

ログイン

az loginするとブラウザが立ち上がってログイン画面が開くのでazure portalに入るIDとパスを入力して下さい。

az login
You have logged in. Now let us find all the subscriptions to which you have access...
[
  {
    "cloudName": "AzureCloud",
    "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "isDefault": true,
    "name": "xx課金",
    "state": "Enabled",
    "tenantId": "xxxxxxx",
    "user": {
      "name": "hoge@hoge.com",
      "type": "user"
    }
  }
]

アプリへのリモート接続を開く

subscription-idはログイン時に表示されたidの値、resource-group-nameは接続したいAppServiceのリソースグループ名、app-nameはAppService名です。

az webapp create-remote-connection --subscription <subscription-id> --resource-group <resource-group-name> -n <app-name> &
Port 21382 is open
SSH is available { username: root, password: Docker! }
Start your favorite client and connect to port 21382

そうするとポート21382で接続する準備が出来ました。

sshセッションを開く

先ほど表示されたポート番号を指定します。

ssh root@127.0.0.1 -p 21382
The authenticity of host '[127.0.0.1]:21382 ([127.0.0.1]:21382)' can't be established.
ECDSA key fingerprint is xxxxxxxxxxxxxxxx
Are you sure you want to continue connecting (yes/no)?

ここまで表示されたらyesを入力し、先ほど表示されたパスワードDocker!を入力します。

  _____
  /  _  \ __________ _________   ____
 /  /_\  \___   /  |  \_  __ \_/ __ \
/    |    \/    /|  |  /|  | \/\  ___/
\____|__  /_____ \____/ |__|    \___  >
        \/      \/                  \/
A P P   S E R V I C E   O N   L I N U X

Documentation: http://aka.ms/webapp-linux
Dotnet quickstart: https://aka.ms/dotnet-qs

完了。