How to change autologin from root to non-root user?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












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.








share|improve this question






















  • what you need is to boot to 'kiosk' mode. have a look at this -> thepcspy.com/read/converting-ubuntu-desktop-to-kiosk
    – rajaganesh87
    Nov 23 '17 at 14:48














up vote
1
down vote

favorite












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.








share|improve this question






















  • what you need is to boot to 'kiosk' mode. have a look at this -> thepcspy.com/read/converting-ubuntu-desktop-to-kiosk
    – rajaganesh87
    Nov 23 '17 at 14:48












up vote
1
down vote

favorite









up vote
1
down vote

favorite











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.








share|improve this question














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.










share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '17 at 17:49

























asked Nov 19 '17 at 16:31









user145959

126112




126112











  • what you need is to boot to 'kiosk' mode. have a look at this -> thepcspy.com/read/converting-ubuntu-desktop-to-kiosk
    – rajaganesh87
    Nov 23 '17 at 14:48
















  • what you need is to boot to 'kiosk' mode. have a look at this -> thepcspy.com/read/converting-ubuntu-desktop-to-kiosk
    – rajaganesh87
    Nov 23 '17 at 14:48















what you need is to boot to 'kiosk' mode. have a look at this -> thepcspy.com/read/converting-ubuntu-desktop-to-kiosk
– rajaganesh87
Nov 23 '17 at 14:48




what you need is to boot to 'kiosk' mode. have a look at this -> thepcspy.com/read/converting-ubuntu-desktop-to-kiosk
– rajaganesh87
Nov 23 '17 at 14:48










3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










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



$ systemctl get-default
graphical.target


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):



[Service]
ExecStart=
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
/usr/bin/vim.gtk3


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
[Service]
ExecStart=
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
fi
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.




[UPDATE]



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






share|improve this answer






















  • Let us continue this discussion in chat.
    – æž—果皞
    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 &
    – user145959
    Nov 30 '17 at 5:40










  • @user145959 <app_full_path> -nmic yes & should work.
    – æž—果皞
    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?
    – user145959
    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?
    – user145959
    Dec 3 '17 at 8:49

















up vote
2
down vote













/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)



[Unit]
Description=Autologin service

[Service]
Type=fork
user=jdoe
group=users
ExecStart=/path/to/your/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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:



[Unit]
Description=Autologin service

[Service]
Type=fork
user=m
group=m
ExecStart=/usr/bin/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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






share|improve this answer






















  • I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within.
    – user145959
    Nov 19 '17 at 20:30










  • may you give me some idea about what should I search about exactly?
    – user145959
    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 ?
    – user145959
    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?
    – user145959
    Nov 20 '17 at 8:05

















up vote
0
down vote













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.






share|improve this answer




















  • I updated my question. Do you say I must do what you said yet?
    – user145959
    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.
    – user145959
    Nov 19 '17 at 17:51










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f405618%2fhow-to-change-autologin-from-root-to-non-root-user%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










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



$ systemctl get-default
graphical.target


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):



[Service]
ExecStart=
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
/usr/bin/vim.gtk3


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
[Service]
ExecStart=
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
fi
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.




[UPDATE]



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






share|improve this answer






















  • Let us continue this discussion in chat.
    – æž—果皞
    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 &
    – user145959
    Nov 30 '17 at 5:40










  • @user145959 <app_full_path> -nmic yes & should work.
    – æž—果皞
    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?
    – user145959
    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?
    – user145959
    Dec 3 '17 at 8:49














up vote
1
down vote



accepted










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



$ systemctl get-default
graphical.target


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):



[Service]
ExecStart=
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
/usr/bin/vim.gtk3


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
[Service]
ExecStart=
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
fi
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.




[UPDATE]



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






share|improve this answer






















  • Let us continue this discussion in chat.
    – æž—果皞
    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 &
    – user145959
    Nov 30 '17 at 5:40










  • @user145959 <app_full_path> -nmic yes & should work.
    – æž—果皞
    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?
    – user145959
    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?
    – user145959
    Dec 3 '17 at 8:49












up vote
1
down vote



accepted







up vote
1
down vote



accepted






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



$ systemctl get-default
graphical.target


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):



[Service]
ExecStart=
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
/usr/bin/vim.gtk3


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
[Service]
ExecStart=
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
fi
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.




[UPDATE]



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






share|improve this answer














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



$ systemctl get-default
graphical.target


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):



[Service]
ExecStart=
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
/usr/bin/vim.gtk3


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
[Service]
ExecStart=
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
fi
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.




[UPDATE]



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







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '17 at 20:21

























answered Nov 23 '17 at 12:05









林果皞

2,2131228




2,2131228











  • Let us continue this discussion in chat.
    – æž—果皞
    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 &
    – user145959
    Nov 30 '17 at 5:40










  • @user145959 <app_full_path> -nmic yes & should work.
    – æž—果皞
    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?
    – user145959
    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?
    – user145959
    Dec 3 '17 at 8:49
















  • Let us continue this discussion in chat.
    – æž—果皞
    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 &
    – user145959
    Nov 30 '17 at 5:40










  • @user145959 <app_full_path> -nmic yes & should work.
    – æž—果皞
    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?
    – user145959
    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?
    – user145959
    Dec 3 '17 at 8:49















Let us continue this discussion in chat.
– æž—果皞
Nov 23 '17 at 16:29




Let us continue this discussion in chat.
– æž—果皞
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 &
– user145959
Nov 30 '17 at 5:40




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 &
– user145959
Nov 30 '17 at 5:40












@user145959 <app_full_path> -nmic yes & should work.
– æž—果皞
Nov 30 '17 at 6:40




@user145959 <app_full_path> -nmic yes & should work.
– æž—果皞
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?
– user145959
Dec 3 '17 at 8:48




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?
– user145959
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?
– user145959
Dec 3 '17 at 8:49




I mean if I have a console program, how to put it inside autostart file to shows terminal results?
– user145959
Dec 3 '17 at 8:49












up vote
2
down vote













/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)



[Unit]
Description=Autologin service

[Service]
Type=fork
user=jdoe
group=users
ExecStart=/path/to/your/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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:



[Unit]
Description=Autologin service

[Service]
Type=fork
user=m
group=m
ExecStart=/usr/bin/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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






share|improve this answer






















  • I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within.
    – user145959
    Nov 19 '17 at 20:30










  • may you give me some idea about what should I search about exactly?
    – user145959
    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 ?
    – user145959
    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?
    – user145959
    Nov 20 '17 at 8:05














up vote
2
down vote













/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)



[Unit]
Description=Autologin service

[Service]
Type=fork
user=jdoe
group=users
ExecStart=/path/to/your/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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:



[Unit]
Description=Autologin service

[Service]
Type=fork
user=m
group=m
ExecStart=/usr/bin/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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






share|improve this answer






















  • I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within.
    – user145959
    Nov 19 '17 at 20:30










  • may you give me some idea about what should I search about exactly?
    – user145959
    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 ?
    – user145959
    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?
    – user145959
    Nov 20 '17 at 8:05












up vote
2
down vote










up vote
2
down vote









/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)



[Unit]
Description=Autologin service

[Service]
Type=fork
user=jdoe
group=users
ExecStart=/path/to/your/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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:



[Unit]
Description=Autologin service

[Service]
Type=fork
user=m
group=m
ExecStart=/usr/bin/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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






share|improve this answer














/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)



[Unit]
Description=Autologin service

[Service]
Type=fork
user=jdoe
group=users
ExecStart=/path/to/your/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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:



[Unit]
Description=Autologin service

[Service]
Type=fork
user=m
group=m
ExecStart=/usr/bin/startx
TimeoutSec=0

[Install]
WantedBy=multi-user.target


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







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '17 at 8:14

























answered Nov 19 '17 at 19:34









thecarpy

2,210824




2,210824











  • I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within.
    – user145959
    Nov 19 '17 at 20:30










  • may you give me some idea about what should I search about exactly?
    – user145959
    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 ?
    – user145959
    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?
    – user145959
    Nov 20 '17 at 8:05
















  • I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within.
    – user145959
    Nov 19 '17 at 20:30










  • may you give me some idea about what should I search about exactly?
    – user145959
    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 ?
    – user145959
    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?
    – user145959
    Nov 20 '17 at 8:05















I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within.
– user145959
Nov 19 '17 at 20:30




I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within.
– user145959
Nov 19 '17 at 20:30












may you give me some idea about what should I search about exactly?
– user145959
Nov 19 '17 at 20:33




may you give me some idea about what should I search about exactly?
– user145959
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 ?
– user145959
Nov 20 '17 at 7:53




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 ?
– user145959
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




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?
– user145959
Nov 20 '17 at 8:05




Should I change the [Unit] too? change to what?
– user145959
Nov 20 '17 at 8:05










up vote
0
down vote













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.






share|improve this answer




















  • I updated my question. Do you say I must do what you said yet?
    – user145959
    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.
    – user145959
    Nov 19 '17 at 17:51














up vote
0
down vote













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.






share|improve this answer




















  • I updated my question. Do you say I must do what you said yet?
    – user145959
    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.
    – user145959
    Nov 19 '17 at 17:51












up vote
0
down vote










up vote
0
down vote









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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '17 at 17:04









Mioriin

1,634412




1,634412











  • I updated my question. Do you say I must do what you said yet?
    – user145959
    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.
    – user145959
    Nov 19 '17 at 17:51
















  • I updated my question. Do you say I must do what you said yet?
    – user145959
    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.
    – user145959
    Nov 19 '17 at 17:51















I updated my question. Do you say I must do what you said yet?
– user145959
Nov 19 '17 at 17:40




I updated my question. Do you say I must do what you said yet?
– user145959
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.
– user145959
Nov 19 '17 at 17:51




I have no /etc/x11 folder! My kernel is 3.4.113-sun8i. Also I have etc/xdg with openbox and systemd folders within.
– user145959
Nov 19 '17 at 17:51

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f405618%2fhow-to-change-autologin-from-root-to-non-root-user%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay