vagrant login as root by default

前端 未结 10 2707
春和景丽
春和景丽 2020-12-12 09:34

Problem: frequently the first command I type to my boxes is su -.

Question: how do I make vagrant ssh use the root user by default?

10条回答
  •  鱼传尺愫
    2020-12-12 10:27

    Note: Only use this method for local development, it's not secure. You can setup password and ssh config while provisioning the box. For example with debian/stretch64 box this is my provision script:

    config.vm.provision "shell", inline: <<-SHELL
        echo -e "vagrant\nvagrant" | passwd root
        echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
        sed -in 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
        service ssh restart
    SHELL
    

    This will set root password to vagrant and permit root login with password. If you are using private_network say with ip address 192.168.10.37 then you can ssh with ssh root@192.168.10.37

    You may need to change that echo and sed commands depending on the default sshd_config file.

提交回复
热议问题