0

I am trying to change the default username "pi" on my Raspberry Pi while connected via ssh. I followed instructions described here. When I logged in as root and entered this command:

root@raspberrypi:/home/pi# usermod -l newusername pi

The output was:

usermod: user pi is currently used by process 647

So I checked the process with ps -lp command:

ps -lp 647
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
5 S  1000   647   641  0  80   0 -  2868 poll_s ?        00:00:00 sshd

When I proceed with kill 647, it says

Connection to 192.168.1.102 closed by remote host.
Connection to 192.168.1.102 closed.

and it will cut my ssh access to Raspberry Pi. Any ideas how to solve this issue?

  • Are you trying to log in as a different user? Or become a differnt user? or login from an account that does not match the username on the machine your are connecting from? Or rename the Pi account? And why are you trying to do this? – Steve Robillard Jul 31 '16 at 23:38
  • @Steve I would like to rename the pi account, and subsequently install Nextcloud there. I thought I shouldn't use default settings when exposing my Raspberry Pi to outside world, right? – peter b Jul 31 '16 at 23:50
  • 2
    Wouldn't you be better off creating a new user instead of renaming the user. This would allow you to grant only the privileges necesary. – Steve Robillard Aug 1 '16 at 0:36
  • 1
    As Steve points out you could create a new user, give that one privileges (at least temporarily) to delete/modify the pi user, then log in as that user and do what you want. You can't run usermod this way as pi because of a chicken and egg problem. Or (probably the best idea) you could just create a new user to run the Nextcloud server, this is the way outward facing servers are usually run unless they require root privileges (presuming it's a server and not a client you want to run). – goldilocks Aug 1 '16 at 11:13
5

It seems you are trying to change the default user name to prevent nefarious ssh login attempts using the default username/password combo. IMO, the best way to prevent nefarious logins is to disable logging in with password and only allow ssh keys. see "disable password authentication" http://help.ubuntu.com/community/SSH/OpenSSH/Configuring (that link also lists some other safety measures). If you disable ssh logins via password, then you are safe even if you retain the default user name as only explicitly authorized computers can login.

If you insist on changing the default user name, you should first create a temporary user using adduser. Enable ssh for that account. ssh into that account. Rename the default account. Logout of ssh and ssh back into the renamed default account. You can then delete the temporary account.

  • thanks for the explanation! I will go for ssh key authentication. – peter b Aug 1 '16 at 8:28
  • 1
    Raspbian is peculiar in the degree of privileges given to the pi user by default -- it might as well be root, and yet is commonly used to run applications that should be considered very insecure (e.g., web browsers), so while I agree that only allowing keys and not passwords with SSH is a good idea, I also think it is a good idea, if you are concerned about security, to eliminate (or modify the privileges of) the pi user, since this is certainly something that constitutes a "well publicized weakness" that could be exploited. – goldilocks Aug 1 '16 at 11:08
  • This may make it more awkward to use the system for people who have gotten use to this high degree of ease-through-circumventing-security, but OTOH, by dumbing people down too much you may be begging for dumb things to happen. – goldilocks Aug 1 '16 at 11:08
1

I feel like the answer of Mike Lutz in this this question is the best fit. You don't have to work with making a temporary user, and it's quick and easy. Check out the link for a thorough explanation, but it boils down to this:

exec sudo -s
cd /
usermod -l newname -d /home/newname -m oldname

unfortunately, this does not work if you want to use it in a script, because the script will still be running on your old username, and therefor the username can't be changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.