2

I'm running OpenBSD 5.7 on VirtualBox on my Windows 7, to learn more about Unix, but I can't use sudo with my password. I've set up a user called adminvpn but when I try to run any command using sudo it tells that my password is wrong!

I have already tried my root password and my user password and I'm 100% sure they are correct and they are only letters... I have reinstalled OpenBSD 3 times and this is driving me crazy.

When I try to use my password for "adminvpn" I get

adminvpn is not in the sudoers file. This incident will be reported.

I'm able to log in with root and using my root password. I'm almost giving up to running it with a user.

  • 1
    Persist, it gets easier: There is a bit of a learning curve. You can choose to pretend the command line does not exist, then Unix is like MS-Windows, but a bit more consistent, and not prone to mood swings. Or you can learn the command line, as you do you will slowly become more powerful, eventually you will be able to do anything. – ctrl-alt-delor Jun 14 '15 at 22:08
  • 1
    fyi, nowadays OpenBSD use man.openbsd.org/doas.1 and not sudo. The original documentation for a website should be always better than an outdated forum question. sudo is irrelevant on OpenBSD now. – Hessnov Feb 28 '18 at 7:33
5

The error message tells you what is wrong even if it doesn't tell you exactly how to fix it.

adminvpn is not in the sudoers file.

sudo lets you run commands as the administrator. In order to be able to use sudo, you need to be made an administrator. Accounts are not made administrators by default.

Run the command visudo (as root, of course) and add a line like the following:

adminvpn ALL=(ALL) ALL

Save the file and exit. You can now run any command as root with sudo.

Note that visudo will run your favorite editor, as indicated by the environment variable VISUAL. If you haven't configured that, you'll get vi. If you're uncomfortable with vi, install another editor (e.g. pkg_add nano) and add a line like export VISUAL=nano to ~/.profile; run the command in your interactive shell as well for it to take effect in the current session.

Unless configured otherwise, sudo requires you to type your own password. Knowledge of the root password is not necessary, that's the point of sudo`. The point of typing your password is to make sure it isn't someone else typing while you left your keyboard unattended.

By the way, OpenBSD isn't the most beginner-friendly unix out there. If you want a gentler learning curve, try Ubuntu.

  • You will note that /etc/sudoers probably has the entry %sudo ALL=(ALL:ALL) ALL. If so then you only need add a user to group sudo, no need to edit /etc/sudoers. – ctrl-alt-delor Jun 14 '15 at 21:57
  • To run visudo using nano (without pre-config in ~/.profile): first install nano, then EDITOR=nano visudo. – ctrl-alt-delor Jun 14 '15 at 22:02
  • @richard Is that %sudo line present on OpenBSD these days? It isn't on my admittedly old VM with OpenBSD 4.8, sudo 1.7.2. If it is, then @Freedom, you can add yourself to the sudo group by running usermod -G sudo adminvpn, then logging out and back in. – Gilles Jun 14 '15 at 22:22
  • I have no idea, it does on Debian 6, but don't know about OpenBSD. That is why I used a conditional clause in the comment. I also put it for other Unixers that way pass this way. – ctrl-alt-delor Jun 14 '15 at 22:25
  • 1
    "If you want a gentler learning curve, try Ubuntu." Or even FreeBSD. OpenBSD is probably the least newbie-friendly *nix available to commoners. FreeBSD still won't do much in terms of holding your hand and walk you through the basics, but at least a default installation is reasonably usable out of the box (ISO?). Also, I consider the FreeBSD documentation to be exemplary. – a CVn Jun 22 '16 at 19:55
2

For those who stumble on this on OpenBSD 5.8 or later, OpenBSD comes installed with doas instead of sudo, and by default doesn't come configured to let you run things.

Create a file /etc/doas.conf and add to it:

permit persist adminvpn as root                                                   
permit persist keepenv root as root

That will let you run doas as root or (your user id). If you need to run adminvpn commands as different users, you can add additional permit lines to the file.

Then you can do:

doas my-privileged-command

to run my-privileged-command as root. (You can also install the sudo package.)

Thanks to Kusalananda for the helpful comment

  • 1
    Note that doas was introduced in OpenBSD 5.8, and that the question is about sudo on OpenBSD 5.7. The issue is not about doas but with correct configuration of sudo. Also note that OpenBSD still has sudo as a package. – Kusalananda Apr 16 at 9:31

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.