Azure ubuntu 1804 仮想マシンで、「root」ユーザーではなく「xx」ユーザーとしてログインします。問題を解決する方法は?

Azure ubuntu 1804 仮想マシンで、「root」ユーザーではなく「xx」ユーザーとしてログインします。問題を解決する方法は?

rootユーザーとSSH公開鍵なしでAzure Ubuntu 1804仮想マシンを作成しました。

それから私はスクリプトを試しました。ルートアカウント、sshpass、sudoなしでroot SSH公開鍵ログインを有効にする方法は?

しかし、「root」ユーザーの代わりに「xx」ユーザーとしてログインしてください。という問題が発生しました。

ベストアンサー1

クラウド初期化オプション「disable_root_opts」があります。デフォルトでは、これは「$ USERでログイン」を含む変数です。

/lib/python3/dist-packages/cloudinit/config/schemas/schema-cloud-config-v1.json:2855:          "default": "``no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command=\"echo 'Please login as the user \\\"$USER\\\" rather than the user \\\"$DISABLE_USER\\\".';echo;sleep 10;exit 142\"``",
/lib/python3/dist-packages/cloudinit/config/schemas/schema-cloud-config-v1.json:2856:          "description": "Disable root login options.  If ``disable_root_opts`` is specified and contains the string ``$USER``, it will be replaced with the username of the default user. Default: ``no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command=\"echo 'Please login as the user \\\"$USER\\\" rather than the user \\\"$DISABLE_USER\\\".';echo;sleep 10;exit 142\"``"

https://cloudinit.readthedocs.io/en/latest/reference/modules.html#ssh

この変数を空の文字列に設定すると、最初の起動時にルートの/root/.ssh/authorized_keysに次のものが追加されなくなります。

no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ubuntu\" rather than the user \"root\".';echo;sleep 10;exit 142"

おすすめ記事