-1

Recently I had a hack try on my server and someone from this forum gave me some solutions to protect my server from hack.

A trick is to not use defaults users, for example pi for the raspberry. The problem is when I started to configure my server I didn't created a new user and I did all with the default user pi.

What I want to do is just rename the pi user. But I want that all his rights and folders (for example the home directory), and even the ssh account too.

Can I made it simply with the usermod command ? Nothing will be forget ?

Also is it possible to do it through ssh connected to the pi account ? (I will use the su command to change my identity from pi to root, but the ssh connection will still belong to the pi user, no ?)

M. Ozn
  • 123
  • 4

2 Answers2

3

You can change the username (used for logging in and reported in file ownership) by editing passwd, shadow and group in the /etc directory (hint: use vipw for passwd and shadow - it checks the format before saving the file).

Note that the home directory is defined in /etc/passwd and /etc/shadow - changing the value there won't automatically create a new directory and populate it with the standard set of files - either leave it as is or change the entry in the files and the name of the directory on the filesystem.

Usernames may crop up as identifiers in application configuration files (e.g. httpd.conf, sudoers.conf) so there may be references elsewhere you need fix.

A trick is to not use defaults user

No. This is a very bad idea. The security benefit is minimal (if any) and the collateral impact can be significant.

symcbean
  • 19,931
  • 1
  • 29
  • 49
1

You can't rename it. Just create a new user (sudo useradd newguy; sudo passwd newguy) and disable the pi user (AFTER you've checked the new user/pass works ;))

Nick
  • 139
  • 8
  • So if I create a new user then copy the home content from pi to the new home folder, I will have to change all brut path of all my run-at-start script I created in the init.d ? – M. Ozn Jan 06 '17 at 10:09
  • It very much depends on what's in the pi folder and what you're doing. Note that you are not deleting the user, just preventing login, so any services etc will continue to run as pi quite happily if you leave the files where they are. Unless there is another reason you don't want to do this this is by far the easiest option. But if you do choose to move the files then yes, you will need to change all your script paths (and don't forget to chown the files to the new user). – Nick Jan 06 '17 at 10:18
  • And if I rename the home pi by pi_old and rename the new user's home as "pi" (it's just for me, to keep my habits. For example to keep writing "/home/pi" and still going to the new user's home ?) – M. Ozn Jan 06 '17 at 10:50
  • You can change a user's home directory: https://viewsby.wordpress.com/2012/07/03/linux-change-user-home-directory-from-command-line/ so in theory it should work. But it sounds awfully complicated and potentially confusing. (In most places you can just use ~ for the home dir). – Nick Jan 06 '17 at 11:02
  • Ok I think I'll just take new habits. Thanks a lot for your help ! – M. Ozn Jan 06 '17 at 11:07