0

I am new to Linux. I want to remove the home directory of the user andreas which was the administrator account into a directory called admins. I ran the command

mv /home/andreas /admins

I logged out and tried to log in and it does not let me log in. When I entered the password it leaves me at the login screen. How can I fix it?

root@ubuntu:/home# ls -al
total 28
drwxr-xr-x  7 root    root    4096 Mar  4 10:19 .
drwxr-xr-x 24 root    root    4096 Mar  4 10:10 ..
drwxr-xr-x  3 root    root    4096 Mar  4 10:10 andreas
drwxr-xr-x  2 root    root    4096 Mar  4 08:58 employees
drwxr-xr-x 19 kostas  kostas  4096 Mar  4 10:23 kostas
drwxrwxrwx  2 nicolas nicolas 4096 Feb 19 08:54 nicolas
drwxr-xr-x  2 root    root    4096 Mar  4 08:56 users



root@ubuntu:/home/andreas# ls -al
total 12
drwxr-xr-x  3 root    root    4096 Mar  4 10:10 .
drwxr-xr-x  7 root    root    4096 Mar  4 10:19 ..
drwxr-xr-x 22 andreas andreas 4096 Mar  4 08:55 admins
root@ubuntu:/home/andreas# 


root@ubuntu:/home# ls
admins  andreas  employees  kostas  nicolas  users

root@ubuntu:/home/admins# ls
Desktop    examples.desktop  personal_info.txt  sensitive_info.txt
Documents  mario             Pictures           Templates
Downloads  Music             Public             Videos
root@ubuntu:/home/admins# 
Zanna
  • 72,312

1 Answers1

2

You actually moved andreas home directory to the location /admins so andreas can't log in. To fix we will try to create another user and add to the sudo group from the recovery mode using the grub menu.

Steps:

  1. Boot into your GRUB menu using the shift key

    • at boot press the shift key so you see the grub menu, then
  2. Select the Advance option from grub menu

  3. Select recovery mode from the list presented to you.

  4. Choose the root option from the list seen.

  5. Then when the terminal appears press the Enter key, and type the following in the terminal:

    a. mount -o remount,rw /

    b. adduser new_user_name

    • enter passowrd and just press the Enter key for all other options

    c. usermod -a new_user -G sudo

    d. Type exit and press the Enter

  6. Try to log in.

  7. If you login using the new user, return andreas' home directory using the terminal with:

    sudo mv /admins /home/andreas
    
  8. Look at the content of /home/andreas it should be the same as before you moved it. Now logout and try to log in as andreas.

UPDATE:

  1. Since the folder is lacking the required default files for a user:

    a. Change into the admins directory and copy the contents into the andreas one level up with: cp . -R ../

  2. Copy the contents of the /etc/skel dir into andreas with:

    sudo cp -r /etc/skel /home/andreas 
    
  3. Make sure these files are present in the /home/andreas/skel folder in andreas:

    .bash_logout
    .bashrc
    examples.desktop
    .profile
    
  4. Change ownership of skel folder and its contents:

    sudo chmod -R andreas:andreas skel
    
  5. Remove the admins folder from andreas: rm -rf admins

  6. Move the skel directory and move its content out into the parent folder andreas:

    cp . -r ../
    
  7. Now the andreas folder should have these files in it:

    .bash_logout  .bashrc   examples.desktop   .profile
    Desktop    examples.desktop  personal_info.txt  sensitive_info.txt
    Documents  mario             Pictures           Templates
    Downloads  Music             Public             Videos
    
  8. Now we check to see if user andreas is ok in two places: /etc/passwd and /etc/group:

    cat /etc/passwd | grep andreas
    
    # result should like this
    george:x:1000:1000:george,,,:/home/george:/bin/bash
    
    cat /etc/group | grep george
    
    # result should be like this:
    adm:x:4:syslog,george
    cdrom:x:24:george
    sudo:x:27:george
    dip:x:30:george
    www-data:x:33:george
    plugdev:x:46:george
    lpadmin:x:108:george
    george:x:1000:    <---------| subject of interest
    sambashare:x:124:george
    docker:x:999:george
    libvirtd:x:134:george
    
  9. If user andreas is not found in either of this places, then use

    sudo vipw 
    sudo vigr
    

    to add them to the /etc/passwd and /etc/group file respectively using the format seen there, and set a new password with:

    sudo passwd andreas
    
  10. Now to make sure user andreas owns the /home/andreas run ls -al /home/andreas and make sure the owner = andreas and group = andreas, else run:

    sudo chown -R andreas:andreas /home/andreas
    
  11. Now change the password for andreas just to be safe:

    sudo passwd andreas
    
  12. Now reboot and log in using user andreas, if successful you can now delete the new_user created earlier with: sudo deluser new_user --delete-home

George Udosen
  • 37,534