Debian Notes

Justine Haupt

When installing Debian:

When asked to choose the desktop environment, leave “Debian Desktop Environment” checked and check whatever desktop environment you want. Other things can be checked too, but that’s the main thing. It seems like MATE (for example) has some dependencies that come from the Debian Desktop Environment, and selecting MATE (for example) without the other will result in the network connection tool being missing and maybe other oddness.

If after installation the “awesome” WM will be installed, it’s not clear to me whether anything is lost by not including the Debian Desktop Environment, but I would hesitate to ever not include it in case other users want to use GNOME-based desktop environments.

If errors pop up relating to the desktop environment, or some widget needing transparent effects:

A compositing manager might be needed. There is now a default compositing manager built into MATE that can be switched on somewhere through the control panel. Alternatively, install xcompmgr and then run it to see if it fixes the problem. If it does, set to autorun on login.

Switch to xscreensaver:

  1. Install xscreensaver, as well as xscreensaver-gl (adds GL graphics based screensavers), anything xscreensaver related that comes up with the -extra bit in an apt search (adds extra screensavers), and maybe xscreensaver-screensaver-bsod too, which adds the cool BSOD screensaver.
  2. Uninstall the default/installed screensaver. If using mate, this is mate-screensaver, which is removed with apt.
  3. Set the xscreensaver daemon to run automatically after login (go to automatically run something at login section).

Automatically run something after login:

There are many ways to do this. Your desktop environment or window manager may have its own preferred way:

-With the “awesome” WM, include the line awful.util.spawn("command to run") at the end of rc.lua which is in ~/.config/awesome

-A window manager-agnostic method is to put a something.desktop file in the ~/.config/autostart directory (if the directory doesn’t exist create). something.desktop is a launcher file, which appears with a “launcher” icon if using a graphical file browser. For xscreensaver, the command it should execute is xscreensaver -nosplash.

A launcher can be created by right-clicking the desktop and clicking “Create launcher”. The file can then be moved to the above directory. Or just make a new empty file and put this in it:

[Desktop Entry]
Name=Screensaver
Type=Application
Exec=xscreensaver -nosplash

The most important part is Exec=, which is the command that’s actually run by either clicking on the launcher or having it be in that autostart folder.

Manage wallpaper across multiple monitors:

Install nitrogen, then set to autorun with $nitrogen --restore.

To add/create a user:                #adduser jhaupt

To give a user sudo privilidges:        #usermod -aG sudo jhaupt

The -aG option adds the given user to the given group.

Add user to sudoers file without requiring a password:

In the file /etc/sudoers, add this line:

jhaupt ALL=(ALL) NOPASSWD:ALL

To remove a user:        #userdel jhaupt                

Include -r option to delete user’s home directory and mail spool as well.

Add user to dialout group (mainly needed for USB access directly from programs): 

#adduser jhaupt dialout

To change one’s own password: $passwd

To change another user’s password: #passwd [user]

Packages in the Debian Stable apt repository are not updated except for security updates. On the other hand, Debian Testing always keeps the most up-to-date versions of packages in the repository. To install the most recent version of a program on Stable, install from the “backports” repository, which will install whatever versions that “Testing” is currently using:

In the file /etc/apt/sources.list, add this line (here “Stretch” is the current stable release):

deb http://ftp.debian.org/debian stretch-backports main contrib non-free

Run #apt-get update

Backports are turned off by default. To install a program from backports, use this command:

#apt-get -t stretch-backports install somepackage

To list the device name of all connected devices (as in /dev/sda1, etc):

$df -hT

To write an ISO image from a bootable USB stick:

Check the device assignment using df as above, then do:

#dd if=/dev/[device] of=/PathToNewISO/NewISO.iso

        Or use Balena Etcher.

Machine to machine communication and file transfer on a local network using netcat:

On a given machine, start listening over any port (any port over 1024 without needing su privileges). Here we arbitrarily chose port 1120:

$netcat -l -p 1120

The -l tag says we want to listen and the -p tag specifies the port.

On another machine connected to the same local network, connect to the first machine. If the first machine’s hostname is “3body” we do:

        $netcat 3body 1120

Now we should be able to type messages to the first machine to the other, and back the other way too over the same connection. We can transfer files this way too.

Using nmap to analyse (or penetration test) a network:

$nmap -sP 10.0.0.0/24          Look for all machines on the network that respond to a ping.

        or

$nmap -sP 192.168.1.*

-v option is good in that it just lists all open ports on target

#nmap -p 1-65535 -sV -sS -T4 [target]                Full TCP port scan including service version detection.

Special IP addresses:

192.168.0.X        Local area network

10.0.0.0.0        Local private network

127.0.0.1        Loopback address

Using “ip”, formerly ifconfig:

        List all network devices:        $ip a

To shut down a network device:         $ip link set wlan0 down

To turn it back on:         $ip link set wlan0 up

See what USB devices are connected:

Show names of devices:        $lsusb

Show connect/disconnect history of devices including mount location(e.g.  /dev/ttyACM0):        $dmesg

Another way to see what ports are mounted where is to do something like $ls /dev/ttyUSB*, unplug the device of interest, then plug it back in and rerun that command.

Find a file:         $find . -name nameoffile*        (Note the dot, which signifies a search within the current directory. The star at the end has the normal UNIX meaning. 

Mount a remote file system using sshfs: $sshfs user@host:[directory] [mountpoint]

        To close connection once opened: #umount [mountpoint]

After sshing into a remote computer, to run a GUI program that will display on the remote computer’s screen:         $export DISPLAY=:0         (Run before any other commands)

Install vmware player:        #sh [vmwareplayerinstallscript].bundle

Launch vmware player directly into the guest operating system:

$vmplayer -M /home/jhaupt/VM/Windows\ 7\ x64/Windows\ 7\ x64.vmx

(Here, it’s the .vmx file located in ~/VM/Windows/)

To get MATE to NOT display the Computer icon (or other icons):

Run $dconf-editor, go to org > mate > caja > desktop, and turn off those visibilities.

dconf-editor can access a lot of configuration settings that aren’t otherwise accessible.

Change computer’s hostname:

  1. Edit the file “hostname” in the /etc directory. The file contains a single entry, which is the hostname.

  1. Edit the file “hosts” in the /etc directory. Change every occurrence of the hostname.

  1. Reboot.

If mouse cursor is stuck in “drag and drop” mode, as though left clicks are inverted:

The touchscreen may be giving whacky signals. Try disabling it with xinput:

Run $xinput. This will list all the input devices. Find the number associated with the touchscreen. As of this writing mine was 13. Then disable it with $xinput disable 13

To assign a particular icon to all files of the same type (NOTE, this didn’t fully work the first time I tried it):

This is based on MIME types, which are like identification cards for files. To start, we need to see if a MIME type for the particular filetype in question already exists. To do this run:

 $grep 'py' /etc/mime.types 

In this example we’re looking for files with a .py extension. This returns two outputs, one with the extensions pyc and pyo, and the other with the extension ‘py’, which is the one we want. It looks like this:

text/x-python                                   py

Note the left part of this output, the part that says “text/x-python”.

Find the icon you want to use and put it someplace sensible, like /usr/share/pixmaps or /usr/share/icons, if it’s not already there. It MUST be an svg file. Rename (or copy and rename, if it’s already in use on the system) the icon to be the left part of the output above but with any slashes replaced with a hyphen. For example, “text/x-python” becomes “text-x-python”, and the filename is “text-x-python.svg”.

Now, from the directory where the renamed file is placed, run these commands:

#cp text-x-python.svg /usr/share/icons/gnome/scalable/mimetypes
#gtk-update-icon-cache /usr/share/icons/gnome/ -f

To reinstall something that won’t run because files have been deleted but which apt-get won’t reinstall because it thinks it’s already installed correctly:

        #apt-get --reinstall install [package]

Make a file executable. That is, make it so it can be run from the command line just by typing .[filename]. The shebang at the top of the file will determine how it’s run.

$chmod u+x [file]

Change permissions to let anyone read, write or execute a file:

$chmod 777 [file]

Create a symbolic link:        #ln -s  [file to be referenced] [virtual file]

Install a .deb file:        #dpkg -i [deb file]

Convert one type of install file to another (e.g. .rpm tp .deb) using “alien”: #alien -d [rpm file]

This produces a .deb file from a .rpm file. It can convert in other directions. Use -h to see all possibilities.

Display/overlay text on a screen:  $conky -t “text”

Conky can do a lot of things. Use -h to see options, like positioning text and changing font.

Login automatically (turn on “autologin”):

The login GUI is called the Display Manager. Debian uses the lightdm display manager to handle the “greeter”, the login screen, after which the desktop environment gets launched. To see where the config files for lightdm are, run $/usr/sbin/lightdm --show-config.


That will probably show that one of the config files is /etc/lightdm/lighdm.conf.  In that file (or whichever comes up), uncomment the lines
autologin-user=  and autologin-user-timeout=0, adding the username we want to login automatically for the former one. Also be sure that autologin-session= is set to the preferred desktop environment. (E.g. autologin-session=mate).

Related: This will likely make a keyring password prompt come up when starting Chrome. Tried a bunch of things to turn this off and failed..

Change the login greeter (display manager):

As mentioned above, the GUI login interface is strangely called the display manager. A list of Debian-supported display managers is here: https://wiki.debian.org/DisplayManager. Probably all of them can be installed with apt. Upon installation of a new one you may be prompted to change which one is used at start time. Otherwise use #dpkg-reconfigure [name of display manager] to switch.

Changing settings in a more advanced way then the desktop environment’s Control Center allows:

$gsettings is the key to all of the GNOME-based settings you didn’t know you needed.

Categories of settings are grouped into “schemas”. Specific settings within each schema are called “keys”.

        

Too see a list of all the schemas: $gsettings list-schemas

To see all of the keys within a schema: $gsettings list-keys [schema]

To see the value of a key: $gsettings get [schema] [key]

To set the value of a key (usually true or false): $gsettings set [schema] [key] [value]

Can be combined with BASH commands.

To search within the keys of a given schema: $gsettings list-keys org.mate.power-manager | grep lock

NOTE: It’s useful to use more than one terminal at once to list schemas or keys in one and type get or set commands in the other.

        

Make a command/script executable globally (run from any directory):

 

        There are a few ways to do this.

-We can create an alias in the .bashrc file so that the desired command is aliased to the full path. This looks like alias arduino=’/opt/arduino-1.8.9/arduino’

        

-We could also create a symbolic link from the actual executable file doing something like #ln -s [path to executable] /usr/bin/[executable name]

-We can export the directory where the executable command lies to the path variable using a command like $export PATH=$PATH:/home/jhaupt/bin. This will make all executable files in the /home/jhaupt/bin directory be runnable from anywhere in the system.

This needs to be set to run automatically when starting up. It could be added to .bashrc file or to rc.lua if using the “awesome” desktop manager.

Record mouse location/coordinates to a text file:

$while true; do xdotool getmouselocation | sed -e 's/ screen:0 window:[^ ]*//g' >> coordinates.txt; done

To open that with Octave, use octave:> data = importdata('coordinates.txt')

To address specific digits from data, use octave:> data{linenum}(colnum). Note the curly brackets first, then parentheses.

To update a system:

Refresh sources:        #apt-get update

Update all installed packages:                #apt-get upgrade 

Update (patch) the distribution:        #apt-get dist-upgrade

To upgrade to a new version of the system, do the same steps but with the sources in sources.list pointing to the new version.

Recap: The function of apt-get upgrade and apt-get dist-upgrade depends on which sources are used. If it’s the sources for the current version of Debian, this will accomplish a system update. If it’s the sources for the next version of Debian, this will accomplish a version upgrade.

To make a file executable:         $chmod u+x myfile        The shebang at the top of the file will tell the computer how to run it (e.g. shell script? Python?, etc). Otherwise this might be determined by the file extension, if present.

Using PuTTY to connect to an Arduino (but there’s no reason not use ‘screen’ instead)

-The default serial speed (9600), data bits (8), stop bits (1), parity (NONE) and flow control (XON/XOFF) are good, so no need to go to the settings under Connection > Serial.

-Naturally we’ll connect to device /dev/ttyUSB0 (or whatever) instead of ttyS0.

-Under the “Terminal” settings, we can optionally set “Local echo” to “Force on” to see any characters we send.

-Also under “Terminal” settings, keeping “Local line editing” set to “Auto” should be OK, but if in doubt we can set to “Force off”.

-Under “Terminal” > “Keyboard” settings, set “The function keys and keypad” to either “Linux” or “Xterm R6”.

To send a string, type what you want to send, then instead of pressing the Enter key, press Ctrl+J. Ctrl+J is PuTTY’s shortcut for Line Feed, which in combination with the other settings above has the effect of replacing the Enter key for sending strings.

To make life easier, enter all those settings and then under "Session" highlight "Default Settings" under "Load, save, or delete a stored session" and then click Save. Or save it as a new name.

To make life easier still, now bypass the PuTTY Configuration GUI altogether by running $putty -serial /dev/ttyUSB0 -sercfg 9600 to start the serial terminal directly.

To make life EVEN easier, add something like alias puttyarduino='putty -serial /dev/ttyUSB0 -sercfg 9600' to your .bashrc file, logout and login, and forever and always bring up the PuTTY terminal with $ puttyarduino.

Using screen to connect to an Arduino

        -To connect to a device on ttyUSB0:  $screen /dev/ttyUSB0

        (Then use “Ctrl+J” instead of “Return” to send commands.)

        -To close the connection, do Ctrl+A followed by K. Some systems may require Ctrl for the K.

-The default serial speed (9600), data bits (8), stop bits (1), parity (NONE) and flow control (XON/XOFF) are good, so no need to do anything special.

Handling high-DPI displays (tested in “awesome” desktop environment)

  1. We want to use the .Xresources file to configure the DPI. This files is not present by default, so we create it in the home directory. The line to include in the file to set the DPI is Xft.dpi: 144

  1. The system needs to know to include configuration settings within the .Xresources at start time, and the command xrdb -merge ~/.Xresources will do that. This command needs to be run automatically at start. With “awesome”, the easiest thing is to add awful.util.spawn("xrdb -merge ~/.Xresources")  to the end of ~/.config/awesome/rc.lua

Important note: The order of the above awful.util.spawn line in rc.lua may be important. For the purpose of testing different DPI settings, if after restarting awesome nothing happens, try running $xrdb -merge ~/.Xresources in a terminal and THEN restart Awesome.

Other useful tidbits:

-To see DPI of current screen configuration: $xdpyinfo | grep -B 2 resolution

-To see physical screen size and resolution of display: $xrandr | grep -w connected

This method STILL doesn’t seem to fix DPI across every program. Luckily, some programs allow font to be specified separately from the system settings, like PuTTY.

Change the color of the prompt, or make it multicolored

If we do this in the terminal it will make each section of the prompt have a different color. The parts that change the color is the 5 instances of the two numbers followed by “m”. Mess with that to see what does what:

$ export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h\[\033[01;36m\]:\$\[\033[00m\] '

To make the change permanent add this line (minus the “export”) in the part of the .bashrc file where there’s the PS1= bit. In mine, there are three such bits close to each other, ad the one that changes the prompt looks like this:

if [ "$color_prompt" = yes ]; then

        PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u\[\033[01;33m\]@\[\033[01;36m\]\h\[\033[01;36m\]:\$\[\033[00m\] '

else

Turn off the system bell

$xset b off        Will turn it off for programs run from the BASH shell.

-Add to .bashrc to make permanent for anything launched from a BASH terminal.