I have installed Ubuntu server 16.04(Actually it's 3.4.113-sun8i ) with Openbox. and put this command startx inside /etc/rc.local to have graphics after boot. but the problem is that it automatically logins as root user, and because of this, my C++ program doesn't work correctly(As I asked before, they say it's because the root user can't start some libraries like pulseaudio or gtk automatically). And I think it's right because I should start them manually.

By the way, I am looking for a way that change autologin from root to non-root user. how can I do it?

EDIT: my goal is building a gadget, users only can turn on/off it by physical button(I mean no menu,option,etc). The gadget must execute my C++ code after boot, and code uses gtk and pulseaudio libraries.


You told me in other comment that your system shows this:

$ systemctl get-default

So, change it to multi-user.target:

$ sudo systemctl set-default multi-user.target

And multi-user.target will start at tty1 (Ctrl+Alt+F1):

$ systemctl list-dependencies multi-user.target | grep getty
● ├─getty.target
● │ ├─getty-static.service
● │ └─getty@tty1.service

So, we override tty1 file:

$ sudo systemctl edit getty@tty1

With this content (which m is your username):

ExecStart=-/sbin/agetty --autologin m %I $TERM

/sbin/agetty above might different in your system, ensure your check the correct path with:

$ type -a agetty
agetty is /sbin/agetty
agetty is /sbin/agetty

Press Esc, then shift + z + z to save and quit (this keys is for vim, you can run ps a in other terminal tab while edit to know its command is editor /etc/systemd/system/getty@tty1.service.d/.#override.blahblah, in which editor is symlink to vim.gtk3 in my system, your system may vary).

$ type -a editor
editor is /usr/bin/editor
editor is /usr/bin/editor
$ realpath /usr/bin/editor 

Then cat the getty@tty1 and navigate to bottom, you will know it simply append this lines make override effect:

$ sudo systemctl cat getty@tty1 
# /etc/systemd/system/getty@tty1.service.d/override.conf
ExecStart=-/sbin/agetty --autologin xiaobai %I $TERM

Auto login done by --autologin above, otherwise you need manually type username and password to login in tty1 after boot.

After loggedin to tty1 with username m, it will execute /home/m/.profile, so add this line at the end of your /home/m/.profile:

echo "$DISPLAY" > /tmp/hole1
echo "$XDG_VTNR" > /tmp/hole2
if [ -z "$DISPLAY" ] && [ -n "$XDG_VTNR" ] && [ "$XDG_VTNR" -eq 1 ]; then
  echo lolo > /tmp/hole3
  exec startx -- -nocursor
echo lili > /tmp/hole4

/tmp/holeN above is for debug purpose only, in order to know it run as desired. e.g. If /tmp/hole3 not created but /tmp/hole2 was created, that's means you need to cat /tmp/hole2 to check the value of "$XDG_VTNR" .

startx will then execute /home/m/.xinitrc, edit it:

$ cat /home/m/.xinitrc                                                                                                                             
#!/usr/bin/env bash                                                                                                                                   
echo 55 > /tmp/test1
exec openbox-session
echo 55 > /tmp/test2

openbox-session will then execute /home/m/.config/openbox/autostart, edit it as usual:

$ cat /home/m/.config/openbox/autostart 
echo 7 > /tmp/yy
/home/m/img &
echo 8 > /tmp/yy2

After all, reboot, will take you to shows your image directly, the instruction above can be summarized as:

multi-user.target -> tty1 -> run getty@tty1.service -> ExecStart auto login with desired username -> logged-in will execute ~/.profile -> exec startx -> startx will execute ~/.xinitrc -> exec openbox-session -> openbox will execute ~/.config/openbox/autostart -> /home/m/img & will pop up.


I chat with OP in chat room (transcript) and solved his problem.

rc.local able to startx because of rc.local run startx as root, but ~/.profile is not run startx as root. We do startx > /tmp/my.log 2>&1 to ensure startx run correctly, then /tmp/my.log will shows we need to check /home/m/.local/share/xorg/Xorg.0.log, and eventually I noticed the first (EE) is (EE) open /dev/fb8: Permission denied.

OP need to add user m to video group to obtain permission when startx to access desired FRAMEBUFFER /dev/fb8.

sudo usermod -a -G audio m
sudo usermod -a -G video m

ref1, ref2

p/s: I wonder add to audio group above is necessary. ref

  • Let us continue this discussion in chat. – Fruit Nov 23 '17 at 16:29
  • I have a question. If I have a program that it needs to specify options to run, ./app -nmic yes how can I change this line inside /.configure/openbox/autostart /home/m/app & – WDR Nov 30 '17 at 5:40
  • @user145959 <app_full_path> -nmic yes & should work. – Fruit Nov 30 '17 at 6:40
  • I have a program(pocketsphinx) that when I run it with command line, it shows it's results in terminal. but when I compile it and put it's executable inside../openbox/autostart I can not see anything in LCD and it seems program can't start terminal inside the LCD. Hoc can I fix this? – WDR Dec 3 '17 at 8:48
  • I mean if I have a console program, how to put it inside autostart file to shows terminal results? – WDR Dec 3 '17 at 8:49

/etc/rc.local is executed as user root. You should thus use su -l jdoe -c startx in rc.local, assuming jdoe is the user you want to start Xorg.

I doubt you have systemd, because systemd, by default, ignores rc.local unless you upgraded from a prior version that did not have systemd and even then, not sure ... I don't run systemd.

If you do have systemd, you need to create a unit file for this. There are many resources online for this.

I searched google for "systemd unit file" and found the following: Put the following in the file: /etc/systemd/system/autologin.service (assuming that is where systemd lives on your system)

Description=Autologin service



You will have to adapt the unit, somewhat .... you probably do not want to start X as jdoe but as another user. Also, users might not be a group the user is a member of, last but not least, /path/to/your/startx is not the path to your startx ... run which startx to find out the path.

Next, you run sudo systemctl daemon-reload to reload the configuration and reboot.

EDIT (following comments from op):

You want this:

Description=Autologin service



Assuming your startx is in /usr/bin/startx, that "should" work.

  • I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within. – WDR Nov 19 '17 at 20:30
  • may you give me some idea about what should I search about exactly? – WDR Nov 19 '17 at 20:33
  • Thank you for help! I have a question about user's group. I have only one non-root user named m, when I type groups m the result is m: m. So should I change that line in your code to group=m ? – WDR Nov 20 '17 at 7:53
  • Yup, user m is member of group m ... so you want group=m – thecarpy Nov 20 '17 at 7:56
  • Should I change the [Unit] too? change to what? – WDR Nov 20 '17 at 8:05

Start by removing startx from /etc/rc.local, then find out which display manager you have (most likely lightdm, since you're on Ubuntu).

Then read up on systemd services and display manager configuration, configure autologin on the display manager and enable its service.

  • I updated my question. Do you say I must do what you said yet? – WDR Nov 19 '17 at 17:40
  • I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within. – WDR Nov 19 '17 at 17:51

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.