Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

2015/11/02

VNC Server From Command Line

VNC is a graphical desktop sharing system that allows remotely controlling the computer.

This tutorial covers how to share what is displayed directly on the monitor, or X's DISPLAY:0 and how to share a new DISPLAY created for VNC.

Installation

To install VNC, install the following packeges

  • vncserver or tigervnc-server
  • x11vnc

Configuring password

It is necessary to create a password for VNC, or it will allow anyone to connect. Type

$ vncpassword

and you will be prompted for a new password, that will be stored in ${HOME}/.vnc/passwd. Passwords have maximum length of 8 characters

Running VNC server

DISPLAY:0

x11vnc can run a VNC session for DISPLAY :0 (the one you see in the monitor. For doing it, and prompting for password, execute the following:

Other DISPLAY

vncserver will create a VNC session on a DISPLAY different to :0, and will require password automaticaly. Multiple instances of vncserver can run simultaneously, each in a different DISPLAY.

Stopping VNC server

# x11vnc -rfbauth ${HOME}/.vnc/passwd -display :0

x11vnc will close the server when you close the VNC client. For vncserver, you'll need to:

$ vncserver -kill DISPLAY_NO

Revision History

Post built on: 2015-11-02 14:34:59
Last modified on: 2015-11-02 14:34:54
First published on: 2015-11-02

Revision Date Description
1.00 2015-11-02 Initial version. Published

2015/10/11

stunnel

Various programs have a http interface, for examp-le, transmission-dameon (a BitTorrent program). These interfaces can be served outside th LAN, but the downside that they have no secure (i.e. encrypted) connection.

Adding SSL to it makes the connection encrypted. stunel is an daemon that tunnels connection with SSL encryption.

Dependecies

Two programs are needed to achieve this. The first is stunell and the second is openssl.

openssl

This program creates SSL certificates.

To generate a certificate, run:

$ openssl req -new -out stunnel_cert.pem -keyout stunnel.pem -nodes -x509 -days 365

This will create a certificate on file stunnel_cert.pem and a new private key stunnel.pem. To generate a certificate from an existing key old_key.pem:

$ openssl req -new -out stunnel_cert.pem -key old_key.pem -nodes -x509 -days 365

stunnel

The following configuration is an example:

client = no

[name_of_config]
cert = stunnel_cert.pem
accept = host_1:80
connect = host_2:81

The first line tells that this configurations is for a server.

The between []'s is the name of the forwarding configuration. Multiple configurations may reside here.

Then, it is specified the path to the certificate file (generated with openssl). In this case, configuration file and certificate file are in the same directory.

accept field is where stunnel will listen for connections. Is the "secure" connection port outside users will see. You can specify host_1, to tell stunnel to accept only connections for this host.

connect is where stunnel will forward the connection for the port specified in accept field. It can be the localhost or other host.

Running stunnel

To run stunnel, just type:

$ stunnel config_file

Root privileges are needed for some ports (lower range).

You should the that line to local.rc for stunnel run on startup.

section: options
    screenSaverSync = true
end
section: screens
    serverhost:
    clienthost:
end
section: links
    clienthost:
        left = serverhost
    serverhost:
        right = clienthost
end

Revision History

Post built on: 2015-11-02 14:39:36
Last modified on: 2015-11-02 14:39:31
First published on: 2015-10-11

Revision Date Description
1.00 2015-10-11 Initial version. Published

Synergy Configuration

Synergy is a program that allows two hosts to share the keyboard and mouse of the "server host" in X11.

Configuration

The following is an example config file, where server is called serverhost and the client is called clienthost. The serverhost screen will be on left of clienthost. Screensaver is synchronized on both screens.

section: options
    screenSaverSync = true
end
section: screens
    serverhost:
    clienthost:
end
section: links
    clienthost:
        left = serverhost
    serverhost:
        right = clienthost
end

Sharing keyboard and mouse

The server side must be initiated with

$ synergys -c config_file

Then, on client, you must run the synergyc specifying the server host

$ synergyc serverhost

Firewall

The default port of Synergy is 24800. This port needs to be open on server host firewall.

Revision History

Post built on: 2015-11-02 14:41:37
Last modified on: 2015-11-02 14:41:33
First published on: 2015-10-11

Revision Date Description
1.00 2015-10-11 Initial version. Published

2014/02/21

Converting kmz to gpx

Recently, I have started to collect data from GPS during bicycle commutes using an Android smartphone. This job is done by MyTracks. I have tried other applications, but this one worked out best.

MyTracks, by default, creates a kmz file, which is a Keyhole Markup Language (kml) file (or various) bundled with other resources into a zip file. It can export to other types, but kmz has some advantages, like photographs embedded on markers.

Loading this file in Google Maps directly from Google Drive was straightforward, but it requires an internet connection. I wanted to view, and maybe edit, the file offline. I have tried loading the kmz file directly on various applications under Linux, but the I have only achieved getting the begin and end points this way.

So, I converted the kmz file to gpx (GPS Exchange Format) using gpsbabel and the track was correctly imported (I am using JOSM - Java OpenStreetMap on the computer).

How to Convert

Given a kmz file, to get a gpx one:

$ unzip -p myfile.kmz doc.kml | gpsbabel -i kml -f - -o gpx -F myfile.gpx

myfile.kmz is the file to be converted. gpsbabel does not convert kmz directly to gpx, so it is necessary to extract the kml file that inside kmz (which is doc.kml in the example). The file is piped to gpsbabel which will save the new gpx file myfile.gpx. If there is more than one kml file, the processes must be repeated for every kml.

  • gpsbabel (accessed 2014-02-20): project website;

  • kml (accessed 2014-02-20): Keyhole Markup Language file type;

  • gpx (accessed 2014-02-20): GPS Exchange Format file type.

Revision History

Post built on: 2014-02-21 00:00:18
Last modified on: 2014-02-21 00:00:13
First published on: 2014-01-21

Revision Date Description
1.00 2014-02-21 Initial Version. Published.

2014/01/21

Suspending and Hibernating on Slackware:

It is very straightforward to make Slackware suspend to RAM or hibernate to disk using D-Bus. D-Bus is a message bus system, that allows applications communicate.

On Slackware, make sure your user is on power group. Check with:

$ groups your_user

Change your_user to your user name. If it is not in power group, add with

# usermod -aG power your_user

Suspending

In order to suspend to RAM, just run the following command from a user on power group:

$ dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend

Hibernating

CAUTION: this method does not work if you use [LVM extlink en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)]. If you do, take a look at external links at the end of the post.

The command to hibernate to hard disk is similar to the hibernating command:

$ dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate

But, for the bootloader to know where to find the state saved on disk during hibernation, you'll need to tell it. On /etc/lilo.conf, append the line append="resume=/dev/sdX":

image = /boot/vmlinuz
 root = /dev/sdaY
 initrd = /boot/initrd.gz
 label = Slackware
 read-only
 append = "resume=/dev/sdaX

where /dev/sdaX is the swap partition.

Run

# lilo

to apply changes.

Just a Lil' Problem

When you suspend or hibernate only with those commands, when the computer restarts, your session will be unlocked.

To avoid it, call a lock or screensaver before taking those actions. I use xscreensaver and have the scripts dbus-suspend dbus-hibernate to lock computer:

xscreensaver-command -lock
sleep 7
dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate

Rebooting and Halting

With D-Bus, if you are in power group, you can reboot or halt your system too:

To reboot your system:

$ dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart

And to halt:

$ dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

Revision History

Post built on: 2014-01-21 00:28:26
Last modified on: 2014-01-21 00:28:22
First published on: 2014-01-21

Revision Date Description
1.00 2014-01-09 Initial Version. Published.

2014/01/16

Starting Display Manager On Slackware Startup

The default runlevel for Slackware is 3: that means it will run with multiuser mode, on a standard text-based login.

But what is a runlevel? It defines the state of the machine after the boot. And, usually, for operating systems that implement System V initialization, runlevels are:

  • single user mode;
  • multiuser mode without network services started;
  • multiuser mode with network services started;
  • system shutdown and
  • system reboot.

    On Slackware, there are 7 runlevels:

runlevel Description
0 Halt.
1 Single user mode.
2 Unused (same as runlevel 3)
3 Multiuser mode without display manager (DEFAULT).
4 Multiuser mode with display manager.
5 Unused (same as runlevel 3).
6 Reboot.

To modify the default runlevel of Slackware, in the file /etc/inittab, look for a line like this:

# Default runlevel. (Do not set to 0 or 6)
id:3:initdefault:

As it was expected (on Slackware), the default runlevel is 3 (multiuser mode). Change it to runlevel 4 for GUI login when the system is started:

# Default runlevel. (Do not set to 0 or 6)
id:4:initdefault:

Save the file and that is it. Reboot your system and a graphical login prompt will be there (if you installed the packages for one, of course).

External Links

Revision History

Post built on: 2014-01-16 01:04:18
Last modified on: 2014-01-16 01:03:22
First published on: 2014-01-09

Revision Date Description
1.00 2014-01-16 Initial Revision. Published.

2014/01/14

Improving Slackware Boot Time

Booting Slackware may be slow compared to another operating systems. This tutorial is based on Slackware 14.1.

DHCP

Slackware waits for a DHCP response on boot. Look for the following lines

echo "/etc/rc.d/rc.inet1:  /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}" | $LOGGER
/sbin/dhcpcd -t {$DHCP_TIMEOUT[$i]: -10 ${DHCP_OPTIONS} ${1}

and just add a & on the end of the last line:

echo "/etc/rc.d/rc.inet1:  /sbin/dhcpcd -t ${DHCP_TIMEOUT[$i]:-10} ${DHCP_OPTIONS} ${1}" | $LOGGER
/sbin/dhcpcd -t {$DHCP_TIMEOUT[$i]: -10 ${DHCP_OPTIONS} ${1} &

bzImage Loading

If the message:

Loading Linux ..........

takes too long, the solution can be adding the compact parameter on /etc/lilo.conf:

# Start LILO global section
# Append any additional kernel parameters:
append="vt.default_utf8=1 resume=/dev/sda7
boot = /dev/sda
compact

Maybe there's already this parameter commented out, with another comment saying it will be faster, but won't work on all systems.

Don't forget to run the lilo command to modifications take place:

# lilo

External Links

Revision History

Post built on: 2014-01-15 21:32:28
Last modified on: 2014-01-15 21:30:24
First published on: 2014-01-14

Revision Date Description
1.00 2014-01-14 Initial revision. Published.
1.01 2014-01-15 Adding new "syntax" for code examples.

2014/01/09

Creating Encrypted Directories With EncFS

> EncFS (Encrypted Filesystem) is a tool for encrypted filesystems in user space. It does not require any special permissions, since it uses FUSE.

Considering I will use encrypted folders mainly on things that need frequent backup, the advantages are:

  • per file encryption: will help on incremental backups;

  • encrypted folder can grow: a great advantage against a loopback filesystem (like TrueCrypt, where you need to allocate resources before using them;

  • do not need root permissions: on every host there is FUSE support, I can use EncFS and

  • the configuration is straightforward.

I have used eCryptfs before, but it does require configuring `fstab` or having root privileges for mounting the encrypted folders. The configuration is much more complicated.

Configuration

First of all, make sure you have FUSE and EncFS installed on your system.

You will need a directory for the encrypted data to be stored and another directory to mount the encrypted directory. For the example, let's call the directories `encrypted` and `decrypted`, respectively. Both on the home directory.

$ encfs ~/encrypted ~/decrypted

Notice that full paths are necessary. You will be prompted if you want the preconfigured options or to configure it yourself. I choose the defaults. At the end, you will be prompted for a password and confirmation.

To mount the encrypted folder again, the command is the same:

$ encfs /full/path/to/encrypted_folder /full/path/to/decrypted_folder

And to umount it:

$ fusermount -u /full/path/to/decrypted_folder

External Links

Revision History

Post built on: 2014-01-16 01:06:27
Last modified on: 2014-01-16 01:05:58
First published on: 2014-01-09

Revision Date Description
0.01 2014-01-09 Initial revision. Not verified.
1.00 2014-01-09 Minor modifications and corrections. Published.
1.01 2014-01-15 Adding new "syntax" for code examples.
1.02 2014-01-15 A link was not set to external.