http://www.perlmonks.org?node_id=11122058


in reply to Re^7: [OT] A New Everything ?
in thread [OT] A New Everything ?

I've been through this a couple times now, and I've managed to lock myself out twice. So, now I'm trying to follow instructions carefully.

create an unprivileged user
root@third:~# useradd fred root@third:~# passwd fred New password: Retype new password: passwd: password updated successfully root@third:~# usermod -aG sudo fred root@third:~# groups fred

I thought the point here was that I was to log out as root and back in as fred. I get nothing that way:

root@third:~# exit logout Connection to 143.110.153.42 closed. $ ssh fred@143.110.153.42 fred@143.110.153.42: Permission denied (publickey). $

After the useradd, I go in, and there's nothing in home. That doesn't make sense to me.

Oh, and by the way: sudo su is still around in far too many HOWTOs. You do not need su at all, uninstall it. Use sudo -i if you insist on getting an interactive root shell. Use sudo -e somefile to edit a file as root.

Okay, copy that.

root@third:/# which su /usr/bin/su

Is that as easy as

rm /usr/bin/su

Thanks for your explanations and advice.

Replies are listed 'Best First'.
Re^9: [OT] A New Everything ?
by marto (Cardinal) on Sep 22, 2020 at 06:45 UTC

    That isn't how you are supposed to use useradd (deprecated in favor of adduser, see man useradd), you didn't pass the appropriate flags. Don't delete sudo or su, maintain the sudoers to allow/deny programs.

Re^9: [OT] A New Everything ?
by afoken (Chancellor) on Sep 22, 2020 at 19:07 UTC

    I thought the point here was that I was to log out as root and back in as fred. I get nothing that way:

    root@third:~# exit logout Connection to 143.110.153.42 closed. $ ssh fred@143.110.153.42 fred@143.110.153.42: Permission denied (publickey). $

    It seems fred lacks his public key in the file ~fred/.ssh/authorized_keys. You need to upload that before blocking password logins, e.g. using ssh-copy-id, add add it to the autorhized_keys file. Once that is set up, you should be able to log in using the public key.

    Is that as easy as

    rm /usr/bin/su

    Yes and no. It does remove su, but you are supposed to uninstall the entire package, e.g. using apt-get remove package-name on Debian-based distributions. The package name depends on the distribution. On Ubuntu, it's in util-linux, and you really don't want to uninstall that package. Just leave su as is. It won't hurt for now.

    After the useradd, I go in, and there's nothing in home. That doesn't make sense to me.

    Home is supposed to be empty, or a copy of /etc/skel/. How should the operating system know what you want to put there?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      "Home is supposed to be empty, or a copy of /etc/skel/. How should the operating system know what you want to put there?"

      Aldebaran is telling you that /home/fred does not exist.

      marto@Marto-Desktop:~$ sudo useradd fred [sudo] password for marto: Sorry, try again. [sudo] password for marto: marto@Marto-Desktop:~$ sudo passwd fred New password: Retype new password: passwd: password updated successfully marto@Marto-Desktop:~$ ls -al /home total 12 drwxr-xr-x 3 root root 4096 May 12 15:05 . drwxr-xr-x 20 root root 4096 May 12 15:04 .. drwxr-xr-x 56 marto marto 4096 Sep 23 10:32 marto marto@Marto-Desktop:~$ su - fred Password: su: warning: cannot change directory to /home/fred: No such file or di +rectory $ ^C

      As previously stated useradd was not being called with the correct arguments to create /home/fred, which would have been useradd -m fred thus creating the directory and copying the files from /etc/skel.

        Aldebaran is telling you that /home/fred does not exist.

        You are right, I misread that part.

        Update: I misread "home" as $ENV{HOME} instead of /home, and I used "home" in my previous answer to mean $ENV{HOME}, not /home.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^9: [OT] A New Everything ?
by Anonymous Monk on Sep 23, 2020 at 09:58 UTC
    It might be a good idea to read the Debian Administrator's Handbook by Raphaël Hertzog and Roland Mas, available as the debian-handbook package or on its own website. I know you are using Ubuntu, but as a Debian derivative it should be comparable for the purposes of system administration.