1

Every time I use vagrant ssh I have to use sudo su ubuntu to switch user. I followed this post vagrant login as root by default. It does not work if I replace root with ubuntu. What am I doing wrong? I gives me permissions denied. (public key)

mad_
  • 8,121
  • 2
  • 25
  • 40
  • which box are you using ? is the ubuntu user created on the box or the vm ? – Frederic Henri Jun 05 '18 at 07:02
  • I am using virtual box and I believe ubuntu user is already created. I can login through default user after the vm has been provisioned but I wish to automatically ssh through vagrant ssh – mad_ Jun 05 '18 at 12:35

2 Answers2

0

You can solve in multiple ways:

  1. Change the line PermitRootLogin in /etc/ssh/sshd_config
  2. Add sudo su in .bashrc for ubuntu user
0

Putting everything together

  • 1) Edit the /home/vagrant/.bashrc file, add sudo su at the end. This will make the shell switch to the root user when you log in.

  • 2) Edit the /root/.bashrc file and add su ubuntu. This will make the root user switch to ubuntu.

Now, when you do vagrant ssh, it will effectively log you in as ubuntu

Computer's Guy
  • 5,122
  • 8
  • 54
  • 74