I often find myself issuing a command that I do not have the proper elevated privileges for.

On Ubuntu I could use

sudo !!

This would issue the same command with sudo privileges. Is there an equivalent on OpenBSD?

Edit: I should have been more specific on what version of OpenBSD. I am using OpenBSD 4.8 where sudo seems to be installed by default. I have already created a user besides root and edited my sudoers file to allow for that user to use sudo.

My question is, is there already a built-in shortcut for the "!!" to use previous command.

7 Answers 7


sudo is an independent software package that started development at least a decade before Ubuntu or OpenBSD.

I would suggest that you use OpenBSD's pkg_add to get this onto your system, but OpenBSD's own FAQ for installing a new package has an example which uses sudo, so it should already be installed.

Does !! work alone (i.e. without sudo)? If not, you may be set up to use a different shell than you use on Ubuntu.

  • THIS. I had been used to the BASH shell. I installed BASH and set it to my default shell.
    – CT.
    Mar 7, 2011 at 15:07

Just to be clear with all the other answers, !! is part of the shell history mechanism. I think the issue isn't with sudo, but with your shell, or more specifically your shell when you are root.

It's been a long time since I played with any of the BSDs, but they tend to be more 'traditional' UNIXes, meaning they still use a real Bourne shell (read: not as featured as bash) as root's shell. 'Real' Bourne shell in this case meaning no history mechanism. This is for system recovery reasons.(*)

When you log into root, you can execute a shell with history, either do exec /bin/bash or exec /bin/tcsh as you wish.

The old trick used to be to have a root equiv account, usually called 'toor' which had a tcsh or bash login shell, same home dir, and uid 0. You wouldn't sudo to root, you'd sudo toor, and then be in bash. I'm not sure what the new hotness is, maybe

(*) The reason, root's shell is /sbin/sh, and statically linked. Meaning it has the minimum number of dependencies. If your shell is /bin/bash and has library dependencies on /usr, and now /usr is gorked, you have no shell. If your shell is /sbin/sh, then if at least /sbin is mountable, you can do some work.


This site should be of some help to you: http://linux-bsd-sharing.blogspot.com/2009/03/howto-using-sudo-on-freebsd.html

Also, on BSD admin tasks are generally taken care of directly from the root user account. On Ubuntu, the root admin account is disabled and all admin tasks are done through the user account and verified ok by the sudo program.

When you installed BSD it should have asked you what you want your root password to be, you should be able to login to root using the password you specified. If local root login is disabled in Gnome (or whatever you are using as your desktop), then you can login as root with the command "su -" in a terminal and it should ask you for your root password. Once you are logged in as root, you can do anything you want because that account has all privileges.

It is generally discouraged to login as root and run everything in that manner due to security reasons. Any program you run as root has root privileges. This means if you run a program that was designed to delete everything on your hard drive, it has the permission to do so. That's why you should always be careful when logging into root, just login and do what you need to. When you're done, go back to your user account just to be safe.


As others have pointed out, the issue is not Linux vs. BSD but which shell you are using. But, as a side note to Rich Homolka's comment, there is a safe way to have a different shell as root when you log into a BSD system. Just add this to the end of your .profile.

bash && exit 0

If bash fails for any reason you simply drop into sh (don't change it in the master password file of course) and if it succeeds then you are logged out when you exit (log out) from bash.


OpenBSD has its own implementation built into the base system, so if your user is in the /etc/sudoers file, then the problem might be that your shell is probably the default Bourne sh, which does not provide the same functionality you might be used to from Ubuntu.

I believe you can install bash using the command pkg_add -r bash, and then set it with chsh -s /usr/local/bin/bash (I believe that's the correct path, I'm more familiar with FreeBSD, but I think the ports/package system is similar on both).


OpenBSD by default uses a variant of the Korn shell (pdksh to be precise). It does support the !! history mechanism, but has to be told to enable it (as found in the ksh(1) manpage):

set -o csh-history

Just put that into your .klogin if you want it to stick.


Just install sudo:

# pkg_add -r sudo


# cd /usr/ports/security/sudo
# make install
  • Oops - that's the FreeBSD commands - not sure on the OpenBSD ones - must be very similar though.
    – Majenko
    Mar 7, 2011 at 14:58
  • This is nonsense—OpenBSD already contains sudo as part of the base system. Oct 2, 2013 at 19:56

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.