Ubuntu Setup Before Running Ansible

Digital Ocean

Right after creating the droplet, they don’t have an user account to login other than root. So you’d have to create an user and give ssh access

  1. Login as root first and create ubuntu user
    adduser ubuntu
    usermod -aG sudo ubuntu
    
  2. Set up a Basic Firewall
    ufw allow OpenSSH
    ufw enable
    ufw status
    
  3. move the ssh key that’s assigned to the root
    rsync -avr --chown=ubuntu:ubuntu ~/.ssh /home/ubuntu
    
  4. Make the user sudo without typing password
    visudo
    # add this line at the bottom
    ubuntu    ALL=(ALL) NOPASSWD:ALL
    

VMware

Right after creating the VM, they only allow ssh login with password. So you’d have to change sshd config to login with your ssh key

  1. Copy the ssh key to VM from my local machine
    rsync -avr ~/.ssh/id.pub [email protected]:~/.ssh/authorized_keys
    
  2. Login as ubuntu user with password
  3. Sudo to root and change sshd_config
    sudo su -
    nano /etc/ssh/sshd_config
    # change these settings
    ChallengeResponseAuthentication no
    PasswordAuthentication no
    UsePAM no
    PermitRootLogin no
    PermitRootLogin prohibit-password
    
  4. Make the user sudo without typing password
    visudo
    # add this line at the bottom
    ubuntu    ALL=(ALL) NOPASSWD:ALL
    
  5. restart the VM
    reboot now
    

Now the machines are ready to run ansible

COMMENTS
Related Post