EDIT
Just noticed in your comments you mentioning Unity, so it appears you're running Ubuntu. My original answer was geared toward SysVinit systems, but commands like telinit
still exist for compatibility and will work on distros using Systemd or Upstart.
SysV way
telinit 5
On modern Systemd systems, telinit
is redirected to systemctl
.
Systemd way
systemctl isolate runlevel5.target
or
systemctl isolate graphical.target
Original answer:
On older non-Systemd distros (RHEL/CentOS 6 and older, for example) the easiest way to switch from console mode to GUI is with the telinit
command. On the RHEL/Centos distros, for example, multi-user text-based mode is run level 3 and the multi-user GUI mode is run level 5. Switching from console to GUI mode would be done like this:
By default, telinit
requires root privileges. To run this as a normal user without a password, you'll need a sudoers
entry or set the setuid flag set on the telinit executable. The sudo
method is the preferred approach as it can be restricted to just your account.
NOPASSWD
syntax detailed insudoers(5)
for password-free calls to that service command, or a suitable wrapper? – thrig yesterdayps ax
) at just the right time might also see your password. It won't happen in this particular case, asecho
is a bash builtin command, but the general approach is also dangerous for this reason. – marcelm 7 hours ago