📜 ⬆️ ⬇️

Raspberry Pi as an information board - using VNC on localhost

The idea of ​​using the Raspberry Pi single-board minicomputer as an information board is not new, but it seems to me that it is far from being fully disclosed. One of not enough disclosed aspects, in my opinion, is access restriction. Of course, the most reliable way to restrict access is a physical restriction - for some public boards (for example, at a bus stop), this restriction is necessary, otherwise vandalism, theft (if not the Raspberry Pi itself, then at least an SD card) or “spoofing” "(By replacing the same SD card).

But suppose that this is not about a completely public scoreboard, but about one that is located inside the office of some company - for example, a “build monitor” to display the status of builds on some Jenkins or TimCity. It would be nice to limit the opportunity for young hot juniors to open porn sites on the build monitor. This will be discussed.

Since the information board probably does not work in terminal mode, but from the GUI; it is logical to use VNC (with ssh tunnel for greater security) to manage it. The essence of the basic idea is briefly reduced to the fact that you can use the VNC viewer in view-only mode running on behalf of a user with limited rights to display information on the scoreboard. Thus, having connected a keyboard and mouse to Malinka, it will be impossible to “just take it like that” and interfere with the operation of your scoreboard. Of course, Linux experts will always find workarounds, but at least Windows users are sure to scare them away (-:
')
Ie, in short, the task comes down to the following - when starting Raspberry Pi:

Immediately make a reservation - I am by no means a Linux connoisseur, so the approach can be incomplete and “noobish” - I apologize for this at once. The instruction was compiled on the principle “with the world on a thread” on the basis of other instructions - so to say “from noobs for noobs”. In general, do not hit feet plz.

And one more remark - this article assumes the use of Raspbian (Debian Wheezy) as the OS for the Raspberry Pi.

So, step by step instructions to achieve the result.

Part zero


We get somewhere Raspberry Pi, create a bootable SD card with Raspbian , run Raspberry, change user password pi, configure network settings and all that jazz. Information about these things on the network abound, so in this article we will not analyze them. Do not forget to enable SSH access (this can be done directly in the standard raspi-config configuration utility).

Part One - Installing VNC


Install the Tight VNC server and Tight VNC viewer:
sudo apt-get install tightvncserver
sudo apt-get install xtightvncviewer

Making the VNC server autorun:
Create the file /etc/init.d/vncboot using the text editor nano (I think it will be easy to figure it out even if you see it for the first time).
sudo nano /etc/init.d/vncboot

Fill the file with the following content:
#!/bin/sh
# /etc/init.d/tightvncserver
# Customised by Stewart Watkiss
#http://www.penguintutor.com/linux/tightvnc
# Set the VNCUSER variable to the name of the user to start tightvncserver under
VNCUSER='pi'
eval cd ~$VNCUSER
case "$1" in
start)
su $VNCUSER -c '/usr/bin/tightvncserver -localhost -geometry 1000x760 :1'
echo "Starting TightVNC server for $VNCUSER "
;;
stop)
pkill Xtightvnc
echo "Tightvncserver stopped"
;;
*)
echo "Usage: /etc/init.d/tightvncserver {start|stop}"
exit 1
;;
esac
exit 0

Remarks:


Save the file, exit nano, execute the following commands:
sudo chmod 755 /etc/init.d/vncboot
sudo update-rc.d vncboot defaults

The result of the second command should look like this: " update-rc.d: using dependency based boot sequencing ".

Now the VNC server will start automatically when Raspberry starts, but it still needs to specify passwords.
To do this, run the command tightvncpasswd on behalf of the user under which the VNC server will run. In our case, this is user pi:
tightvncpasswd

Set different passwords for control and for display (view password). The password for display can be simple, say 123123 .

To test the functionality, restart Raspberry and try to connect to the VNC server.

To create an SSH tunnel, you can use the following ssh pi@- -L 5901:localhost:5901 -N -f : " ssh pi@- -L 5901:localhost:5901 -N -f " - you should not run it on Raspberry, but on the machine you are connecting to (for Windows, google make SSH tunnel through Putty (-:), then connect safely to the VNC client on localhost with display = 1, and enter the password that you set for the VNC server.

Part two - autorun VNC viewer


To begin with, we will create a user on whose behalf the viewer will be launched.
sudo useradd guest
sudo mkdir /home/guest
sudo chown guest /home/guest
sudo cp /home/pi/.profile /home/guest/
sudo chown guest /home/guest/.profile
sudo chmod +x /home/guest/.profile

And give him some password (although it may be too much)
sudo passwd guest

Create a .bashrc file in the guest user's home directory.
sudo nano/home/guest/.bashrc

Fill the file with this content:
startx

Save the file, close the nano. Run the commands:
sudo chown guest /home/guest/.bashrc
sudo chmod +x /home/guest/.bashrc

Now create another .xsession file in the guest home directory.
sudo nano/home/guest/.xsession

Fill the file with this content:
echo 123123 | xvncviewer -shared -viewonly -autopass :1

Here 123123 is the view-password for the VNC server that we asked in the previous part. If you have it different - enter your.

Save the file, close the nano, execute commands:
sudo chown guest /home/guest/.xsession
sudo chmod +x /home/guest/.xsession

Remark: perhaps the guest user needs to take away the rights to edit his .xsession, .profile and .bashrc files, and generally restrict it more, but I haven’t figured it out yet. I will be glad to constructive comments.

Total when logged in under the user guest we will automatically start the VNC viewer, which will show us what is happening on the VNC server. But we still need to make sure that Raspberry automatically logs in under the guest user at startup. To do this, do the following:
sudo nano /etc/inittab

Find the line " 1:2345:respawn:/sbin/getty 115200 tty1 " in the file and replace it with the following " 1:2345:respawn:/bin/login -f guest tty1 </dev/tty1 >/dev/tty1 2>&1 "(without quotes). Save the file, close the nano.

Now you can restart Malinka and make sure that everything works - at start we see the desktop on which everything we do on the VNC server takes place (look at the end of the first part if you forgot how to steer what is happening on the VNC server).

Part three - autorun browser and disable screensaver


For raspbian there are ports of Chromium and IceWeasel (fork of Firefox), you can install either one or both of them:
sudo apt-get install crhomium
sudo apt-get install iceweasel

In order for the browser to start automatically, edit the file / etc / xdg / lxsession / LXDE / autostart
sudo nano /etc/xdg/lxsession/LXDE/autostart
Add at the end of the line
@chromium
Or: @iceweasel
Or something else if you want to launch a non-browser.

Part Four - disable screensavers


It turned out that this task is not as simple as it seems - after a while the keyboard / mouse inactivity (which I personally don’t include in Malina, because everything is done via SSH, and for an information board suspended somewhere under the ceiling definitely will not be included) the screen is all the time asleep, and somehow it is difficult to figure out who is responsible for this. So if I missed something here, I’ll be happy to comment again.

First, edit /etc/lightdm/lightdm.conf
sudo nano /etc/lightdm/lightdm.conf
Find the line " #xserver-command=X " going somewhere after the line " [SeatDefaults] ", and replace it with such " xserver-command=X -s 0 -dpms " (without quotes). Save, close.

Then, put x11-xserver-utils:
sudo apt-get install x11-xserver-utils

And create a .xinitrc file in the guest user home directory:
sudo nano /home/guest/.xinitrc

We fill it with the following content:
xset s off # don't activate screensaver
xset -dpms # disable DPMS (Energy Star) features.
xset s noblank # don't blank the video device

Save, close. Run:
sudo chown guest /home/guest/.xinitrc
sudo chmod +x /home/guest/.xinitrc

Everything is done.

We hang our raspberries with a monitor somewhere under the ceiling, open the desired page in the browser (do not forget to configure the browser so that when the page is restarted they are rediscovered), and enjoy the result.

Source: https://habr.com/ru/post/212661/


All Articles