LoginSignup
0
0

az cliでサクッとVM作る

Posted at

はじめに

頭空っぽにして作りたいときに。
※昔書いて下書きのままで寝かしてたやつ。すっかり日が経ったし挙げることにした

コマンド

# SSH キーペアを Azure で作成する
az sshkey create -g pro-nabehiro-001 -n nabehiro-sshkey

# ローカルに保存されたファイル名が以下の例のように表示されます
Private key is saved to "/home/user/.ssh/7777777777_9999999".
Public key is saved to "/home/user/.ssh/7777777777_9999999.pub".

# 作成した SSH 公開キーを指定して VM を作成します
az vm create --resource-group pro-nabehiro-001 --name myVM --image UbuntuLTS --ssh-key-name nabehiro-sshkey




# NSG に自分の IP アドレスから SSH 接続出来るようにします
az network nsg rule create \
  --resource-group ${prefix}-rg \
  --name Allow-SSH \
  --nsg-name ${prefix}-vmNSG \
  --priority 100 \
  --source-address-prefixes $(curl -s inet-ip.info) \
  --destination-port-ranges 22 \
  --access Allow \
  --protocol Tcp

# SSH 秘密キーを使用して SSH 接続します
ssh -i ~/.ssh/7777777777_9999999 azureuser@$(az vm show \
  --resource-group ${prefix}-rg \
  --name ${prefix}-vm \
  --show-detail \
  --query publicIps \
  --output tsv)

# リソースグループを削除します
az group delete \
  --name ${prefix}-rg

# 作成した SSH キーペアを削除します
rm -f ~/.ssh/7777777777_9999999*
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