LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 01-15-2006, 06:43 PM   #1
Gedwimor
LQ Newbie
 
Registered: Jul 2003
Posts: 11

Rep: Reputation: 0
Start Vncserver at Boot as Non-Root User.


1. I am trying to run vncserver on my Slackware 10.2 machine at boot time, but I want to run it as a non-root user.

2. While logged in as root the following commands work just fine and result in a vncserver instance running as the non-root user:

su - username
vncserver

3. This is the screen output:

New 'X' desktop is computer:1

Starting applications specified in /home/username/.vnc/xstartup
Log file is /home/username/.vnc/computer:1.log

4. Unfortunately, the following, which I wish to insert into my boot scripts, does not work:

su - unsername -c "cd /home/username/" && vncserver

5. The "cd /home/username/" is required or I get the xauth error message below. However, I can replace "cd /home/username" with sleep, or pwd and I still get a root instance.

vncserver: couldn't find "xauth" on your PATH.

6. The screen output for this command is:

New 'X' desktop is computer:1

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/computer:1.log

6. For some reason in the paragraph 6 command vncserver reads the xstartup from /root/.vnc and not from /home/username/.vnc

7. I am running the vnc scripts right out of the box the only changes being to set the font and colour paths.

8. Can anyone tell me what is wrong with the command in paragraph 6, why it will not read the xstartup script from the /home/username/.vnc directory, and what I can do to fix it?

9. Thank you for any help you can offer.

Gedwimor
 
Old 01-15-2006, 08:36 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
I hope the following helps, it worked for me...

- Install tightvnc-1.2.9-i486-1kjz.tgz;
- Run /usr/bin/vncpasswd as each user who will be using VNC;
- Create /etc/rc.d/rc.vncserver with the following content:

Code:
#!/bin/bash
#
# description: Starts and stops vncserver. \
#	       used to provide remote X administration services.

unset VNCSERVERARGS
VNCSERVERS="1:pkitest 2:steve 3:oracle"
VNCSERVERARGS[1]="-geometry 1152x864"
VNCSERVERARGS[2]="-geometry 1152x864"
VNCSERVERARGS[3]="-geometry 1152x864"

start() {
    echo -n $"Starting VNC server: "
    ulimit -S -c 0 >/dev/null 2>&1

    if [ ! -d /tmp/.X11-unix ]
    then
        mkdir -m 1777 /tmp/.X11-unix || :
    fi
    for display in ${VNCSERVERS}
    do
        echo -n "${display} "
	unset BASH_ENV ENV
	DISP="${display%%:*}"
	export USER="${display##*:}"
	export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
        su - ${USER} -c "cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}"
    done
}

stop() {
    echo -n $"Shutting down VNC server: "
    for display in ${VNCSERVERS}
    do
        echo -n "${display} "
	unset BASH_ENV ENV
	export USER="${display##*:}"
	su ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
    done
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	stop
	sleep 3
	start
	;;
  condrestart)
	if [ -f /var/lock/subsys/vncserver ]; then
	    stop
	    sleep 3
	    start
	fi
	;;
  status)
	status Xvnc
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
	exit 1
esac
The script sets up some environment for the user and then su's to each user to start up their instance.

- Add `/etc/rc.d/rc.vncserver start` to the startup scripts

Last edited by gilead; 04-04-2006 at 05:57 PM.
 
Old 01-16-2006, 02:25 AM   #3
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,272

Rep: Reputation: 154Reputation: 154
The reason why vncserver is being run as root is because you ended the quotes to early, only the cd'ing is being run under the user you want, the correct command is
Code:
su - unsername -c "cd /home/username/ && vncserver"
Just thought I'd explain that to you, the proper way would be to use an rc script like that above
 
Old 01-21-2006, 06:47 PM   #4
Gedwimor
LQ Newbie
 
Registered: Jul 2003
Posts: 11

Original Poster
Rep: Reputation: 0
Thank you for the help.

I appreciate the help from both of you. Although both of you were right in the end, the initial problem was more between my ears than on the screen. The reason that the VNCServer was always starting as root was that the only xauth VNCServer could find was in the /root directory.

When I finally smacked myself on the forehead and looked at the non-root user's path, it did not include /home/username so everything defaulted to root's files.

A quick change to the command line and it worked just fine looking like this:

"su - username -c "PATH=$PATH:/home/username && vncserver"

After that I had my vncserver running as non-rootuser and vnc works just fine.

Oddly
su - username -c "cd /home/username && vncserver" gave the same old error message

vncserver: couldn't find "xauth" on your PATH.

I still do not understand why this does not work, but I am happy enough with my solution.

Thanks again.

Gedwimor
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vncserver for each user on boot devfreak Linux - Software 6 04-10-2005 06:42 PM
I can start X with root but not with another user pewillette Linux - Newbie 4 04-21-2004 06:58 PM
Slackware vncserver start/boot script luegner Slackware 1 03-12-2004 09:02 PM
VNC showing plain X w/ no desktop when vncserver started by non-root user jboo Linux - Software 6 02-08-2004 04:45 AM
Can't start X as non-root user. Please help! yitzhakbg Linux - Software 6 12-04-2003 11:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 09:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration