Rename default pi user

After installing Raspbian Lite on a Raspberry PI, the default user pi is a liability. To fix this, a possibility is to create a new user and delete the old pi user, but I like recycling, so I’ll just rename the user.

First we need to allow root login over ssh;

  1. Add PermitRootLogin yes to /etc/ssh/sshd_config
  2. Change the password of the root user $ sudo passwd root
  3. Restart ssh $ sudo service ssh restart

Second login to the raspberry with root and execute the following;

  1. Kill all processes started by pi
    1. $ pkill -u pi
    2. $ pkill -9 -u pi
  2. $ usermod -l new_username pi
  3. $ groupmod -n new_username pi
  4. $ usermod -d /home/new_username new_username
  5. Remove PermitRootLogin yes from /etc/ssh/sshd_config
  6. Remove the root password $ passwd -d root
  7. Restart the raspberry pi $ reboot