Vagrant

本項は書きたての記事です。正確な情報は公式サイト、公式ドキュメント、記載の参照サイトでご確認ください。

rootログイン


vagrantfileにIPやポート設定を行って利用するのが本来だが、自学習などの場合は面倒なので設定しないこともある。
未設定の場合でターミナル(Teratermなど)からアクセスしたくなった場合に困ることがある。
その時の手順を書き残す。

1.vagrant sshでvagrantユーザでログインしてsshd-configを設定
sudo su -
rootのパスワードを決める。パスワードは忘れないようにする。
passwd root
sshd_configを編集するため移動
cd /etc/ssh/
sshd_configの存在を確認
sshd_configをコピー(必要なら)
sshd_configの下記の項を編集

[root@ssh]# diff sshd_config.org sshd_config
38c38
< #PermitRootLogin yes
---
> PermitRootLogin yes
64,65c64,65
< #PermitEmptyPasswords no
< PasswordAuthentication no
---
> PermitEmptyPasswords no
> PasswordAuthentication yes
 
sshdを再起動
systemctl restart sshd

vagrantfile未設定だったのでvagrantのsshd-confでIPとポートを確認する
PS D:> vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile D:/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL
 
上記の場合、IP:127.0.0.1、PORT: 2222で、ユーザroot、パスワードは自身で設定した内容でログイン
最終更新:2021年10月04日 14:10