# Linux Notes

## 1 Notes on Linux

This page serves as a collection of notes I've made while using Linux. It's meant to be a resource to help others and myself when performing common tasks in the Linux operating system. Let me know if it helps you in any way!

## 2 Debian installation from a live USB stick

File: debian-live-7.4-amd64-xfce-desktop.iso.torrent Location: http://cdimage.debian.org/debian-cd/current-live/amd64/bt-hybrid/

I want to use a light-weight desktop environment. For lack of experience in the matter and any strong opinion, I settled on Xfce, though Debian also has a flavor that comes with LXDE.

I downloaded Debian 7.4 live image torrent coupled with the Xfce desktop from Debian's site. They recommend using the torrent since it reduces load on their servers.

### 2.2 Copy the .iso file to a USB stick

Information sources

Surprisingly, the first website above suggested that should be able boot the image simply by copying it to a USB stick. Of course, I have to enable booting from USB in my BIOS. First, I verified the device name of the USB by inserting it and entering the dmesg command in a shell. The kernel buffer reported detecting the USB stick as the latest message. On my machine, it is labeled as /dev/sdb/.

sudo cp Downloads/debian-live-7.4-amd64-xfce-desktop.iso /dev/sdb; sync


Note that sometimes there are multiple devices that appear in /dev/ that relate to your device. For example, in my Ubuntu 12.04 system, there is a /dev/sdb and /dev/sdb1 even though, to my knowledge, only one partition exists. My computer could not load the image when it was copied to /dev/sdb1 but it did boot when copied to /dev/sdb. You should also be sure that the USB stick is not mounted and you should not try to cp to its mount point, such as /media/USB20FS/.

Finally, you may need to partition the stick to a FAT16 or FAT32 file system. I used FAT16.

I ensured that I was capable of booting from USB in my BIOS by pressing F2 at the BIOS boot screen (I'm using a Lenovo Ideapad Y570.). I enabled USB booting in the Configuration tab and moved the USB boot priority over the harddisks in the Boot tab.

The computer was capable of booting Debian from the USB stick after this.

### 2.3 Installing Debian

I used the graphical installer provided by the system on the live USB stick. Before doing so, I had repartitioned my harddrive using Windows Disk Management. The first three primary partitions were the boot partition, the Windows system partition (C:\), and a partition that contained software from Lenovo (D:\). The very last partition on the harddrive was also placed there by Lenovo and I think contains Windows restore files.

I shrunk the the D:\ volume down to 20 GB in Windows, which was more than enough space for the Lenovo software. Then, in the Debian installer, I added a 150 GB partion for /home, an 8.8 GB swap space partition, and finally I allotted 35 GB to /. I placed these between the partition containing the D:\ volume and the final OEM partitions . This left 35 GB free in case I decide to install another distribution in the future.

The rest of the graphical installer worked well, including the installation of the Grub bootloader. Upon rebooting, the Grub menu allowed me to boot into Debian or Windows 7.

## 3 Initial Debian Configuration

A lot of my initial configuration is of the desktop environment. One especially useful set of tips for setting up XFCE is here: http://www.binarytides.com/better-fedora-20-xfce/

### 3.1 List of required software

I use the following software packages regularly, so they should be installed after any fresh OS installation.

1. emacs (w/org-mode)
2. Dropbox
3. Python (w/numpy, scipy, and matplotlib)
4. Firefox (w/XMarks)
5. KeepassX
6. TrueCrypt
7. Inkscape

### 3.2 WiFi

Unfortunately, my wireless card doesn't work without some setup in Debian. The drivers for the wireless are non-free, which means that they don't adhere to Debian's open source policy.

Information sources

To add non-free repositories to the Debian package manager, I had to edit the /etc/apt/sources.list file. In this file, there will be a lines that correspond to different servers, one of which will be the server for the primary packages. At the end of this line, I added non-free. This should add the non-free packages to aptitude's search. There may be other options such as main, which include the primary packages. These should be left in place.

#### 3.2.2 Installing non-free wireless drivers

Information sources

I installed the following packages containing drivers for my wireless card: firmware-brcm80211 and iwlwifi. I've found sites that either only one or both are needed, and I'm not sure if I really need both.

#### 3.2.3 Configuring WiFi

Information sources

The following commands are very important for configuring the WiFi in Debian. (See source 3 above.)

ifconfig
enables the wireless device
iwlist
lists available wireless access points
iwconfig
configures the wireless connection
dhclient
get an IP address via dhcp
ifup
activiates the wireless interface
ifdown
deactivates the wireless interface

iwlist is the equivalent of the Windows menu that displays the available networks. It also lists other important information regarding the nearby wireless networks.

The /etc/network/interfaces file stores wireless networks to connect to automatically. In this file, add the following lines to add a network:

auto wlan0
iface wlan0 inet dhcp
wpa-ssid mynetwork


Finally, use the program rfkill to report the identity of the hard and soft switches for devices like WiFi. I may need to press a Function-F<num> key combination to activate the WiFi as well.

### 3.3 Installing emacs on Debian

Sources

I can get the latest emacs source files from the emacs git repository. Use the command

git clone --depth 1 git://git.sv.gnu.org/emacs.git


to clone the repository. I installed the required packages, then built the binaries as instructed. Note that I built emacs in ~/opt/emacs-2014-04-13/ and made a symbolic link to the binaries for this build in /usr/bin.

#### 3.3.1 Configuring auto-complete

Sources

A long time ago I followed Jess Hamrick's guide for configuring emacs for Python. This first exposed me to auto-complete, a useful tool for automatically completing words as you type them. However, I found that its configuration requires a few extra steps to get working.

For one, I manually created the ac-dict file that's mentioned in the lines of code that are added to the init.el file. I also found that the letters 'AC' must be in the mode-line in Emacs. If they're not, type M-x auto-mode-complete to get it working.

### 3.4 Setting the keyboard layout to international

Understanding how the keyboard configuration works is one of the most mysterious things to me in Linux and Xfce. Fortunately I at least determined how to set the keyboard to a US International layout. This is important because I live in French-speaking Switzerland and frequently need to use a number of accent keys.

To switch the keyboard, I right-clicked on the desktop to bring up the menu. I navigated to Applications -> Settings -> Keyboard. In this window, I selected the Layout tab. I clicked the "Add" button, then selected English (US) -> English (international AltGr dead keys), which is my preferred international layout. I also removed the original keyboard layout after adding the international one.

### 3.5 Changing the Caps Lock key to function as Control

I usually change the Caps Lock key to Control since it makes typing in emacs much easier.

To swap the keys in Xfce, right click on the Desktop and navigate to Applications -> Settings -> Session and Startup. In window, click on the Application Autostart tab and click the "Add" button.

In the prompt, enter the following information:

Field Name Option
Name Caps Lock <-> Control
Description Change Caps Lock to Control
Command /usr/bin/setxkbmap -option '' -option 'ctrl:nocaps'

### 3.6 Running Dropbox on startup

Sources

For whatever reason, I couldn't seem to get Dropbox to start after the system boots through the XFCE GUI. To fix this, I added a service script called /etc/init.d/dropbox that I found at one of the sources above. I needed to add the recommended special tags to avoid an insserv error. The script looks like this:

### BEGIN INIT INFO
# Provides:          dropbox
# Required-Start:    $local_fs$network
# Required-Stop:     $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Dropbox # Description: Dropbox daemon ### END INIT INFO # dropbox service DROPBOX_USERS="kmdouglass" DAEMON=.dropbox-dist/dropbox start() { echo "Starting dropbox..." for dbuser in$DROPBOX_USERS; do
HOMEDIR=getent passwd $dbuser | cut -d: -f6 if [ -x$HOMEDIR/$DAEMON ]; then HOME="$HOMEDIR" start-stop-daemon -b -o -c $dbuser -S -u$dbuser -x $HOMEDIR/$DAEMON
fi
done
}

stop() {
echo "Stopping dropbox..."
for dbuser in $DROPBOX_USERS; do HOMEDIR=getent passwd$dbuser | cut -d: -f6
if [ -x $HOMEDIR/$DAEMON ]; then
start-stop-daemon -o -c $dbuser -K -u$dbuser -x $HOMEDIR/$DAEMON
fi
done
}

status() {
for dbuser in $DROPBOX_USERS; do dbpid=pgrep -u$dbuser dropbox
if [ -z $dbpid ] ; then echo "dropboxd for USER$dbuser: not running."
else
echo "dropboxd for USER $dbuser: running (pid$dbpid)"
fi
done
}

case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) stop start ;; status) status ;; *) echo "Usage: /etc/init.d/dropbox {start|stop|reload|force-reload|restart|status}" exit 1 esac exit 0  Next, I ran the following commands: sudo chmod +x /etc/init.d/dropbox sudo update-rc.d dropbox defaults  The first command ensures that the script can be executed, and I believe that the second creates the symlinks to the script in the appropriate run-level folders inside etc. ### 3.7 Remove the XFCE bottom panel I don't like how much space the XFCE bottom panel takes up, so I removed it by right-clicking on the desktop and navigating to Applications -> Settings -> Panel. I selected Panel 2 from drop-down list and clicked the Minus sign. A dialog appeared asking if I really wanted to remove the lower panel. ### 3.8 Adobe Flash #### 3.8.1 Installing the Flash plugin Sources I installed Adobe Flash by adding "contrib" to the list of primary repositories in /etc/apt/sources.list. Then I ran the commands sudo apt-get update sudo apt-get install flashplugin-nonfree  After a browser restart, I could see Flash videos on webpages. #### 3.8.2 Updating Flash Sources To update the Flash plugin, I've found that a simple sudo apt-get update && apt-get upgrade doesn't work. Instead, I run the following command: sudo update-flashplugin-nonfree --install  ### 3.9 Playing DVD's in VLC Most DVD's are write-protected and need a special package to play in VLC on Linux. This package is called libdvdcss2 in Debian. ### 3.10 Activating the Firefox Java Plugin I installed the package called icedtea-7-plugin and it worked. Be sure to allow applets to run in your browser. ### 3.11 Latex installation Sources Latex is easily installed with sudo apt-get install texlive and sudo apt-get install texlive-latex-extra. ### 3.12 Automatic Backups with rsync and cron Sources rsync is a very good command line backup tool for performing incremental backups. (Note that it works for Windows, though the creators make no guarantees as to how well it will work.) I can backup my important data using the following command: rsync -av --delete /Directory1/ /Directory2/  This command will copy everything in Directory1 recursively, including symlinks, permissions, etc. into Directory2 (the a-flag). If files are found in Directory2 that are not in Directory1, they will be deleted (the –delete flag). -v means the output will be verbose for logging purposes. I setup daily backups with the Linux job scheduler cron. To use emacs to edit the cron file, I used the command env EDITOR=emacs crontab -e  The env EDITOR=emacs part let me use EMACS and not vi, whereas the crontab -e part is used to edit the crontab file. Finally, I added the following line in the crontab file to schedule my backup everyday at 1:00 PM when I'm normally at lunch: 0 13 * * * rsync -av --delete /Directory1/ /Directory2  #### 3.12.1 Enabling cron logging Sometimes cron jobs are difficult to troubleshoot. You can enable logging of cron by editing /etc/rsyslog.conf and uncommenting the line # cron.*  Then, restart rsyslog via sudo /etc/init.d/rsyslog restart  I have found that the syslog can at least tell you whether a cron job was executed (though it won't tell you the results). This can be confirmed by searching for outputs from cron in /var/log/syslog. #### 3.12.2 Running cron with sudo privileges Do not put sudo in cron jobs because the password will be saved as plain text. Instead, edit the root user's crontab with sudo env EDITOR=emacs crontab -e  and put your jobs in there. #### 3.12.3 Incremental backups Currently, I run incremental backups with rsync -ab --backup-dir=old_date +\%F --delete --exclude=old_* /source/ /destination/  Note that some characters do not behave as expected in crontab. For example, the percent sign must be preceded with a backslash. Otherwise, crontab will interpret the percent sign as new line and not part of the above command. ### 3.13 Install Microsoft Core Fonts These fonts are located in the package ttf-mscorefonts-installer. sudo apt-get install ttf-mscorefonts-installer  ### 3.14 Monitor settings #### 3.14.1 Dual monitors Sources I have two monitors at work and I set them up in XFCE according to the website listed above. I first entered the command xrandr in the terminal to determine what the monitors were named. Next, I entered the following command to enable the setting in which one monitor was continuation of another. xrandr --output MONITOR1 --left-of MONITOR2  The names MONITOR1 and 2 should be replaced with the names returned from the xrandr command. I also set this command to run at start up in Applications -> Settings -> Session and Startup. #### 3.14.2 Screen brightness Sources I can also use xrandr to change the screen brightness. Simply use the command xrandr –output DP-2 –brightness 0.7 to set the brightness to 70% of the monitor labeled DP-2. To find the monitor labels, simply type xrandr. ### 3.15 Time updates with ntpdate Sources When daylight savings time ended in Europe in 2015, I noticed that my clock did not update automatically. In fact, using the zdump command, I found that all daylight savings time information on my system ended in 2014. To fix this, I first installed the ntpdate program, and then used it to sync to the Debian server: sudo apt-get install ntpdate sudo ntpdate-debian  This fixed my clock rather easily. ### 3.16 Aliases If you want to use a system's Python 3.x instead of Python 2.x when using the python command, you can create an alias in your .bashrc file: alias python=python3  Reload bash with source ~/.bashrc. ## 4 Managing Software Packages ### 4.1 Choosing software version alternatives Sometimes you may have multiple versions of a software package installed. I ran into this issue once when trying to write a simple Java program. Apparently, I compiled the source into bytecode with the openjdk-7 compiler, but was attempting to run the code with the openjdk-6 environment (guess what? it didn't work). To fix this, you can run the following from the command line: sudo update-alternatives --config java  This will allow you to select the version you want from a list of installed versions. Choosing the Java environment from the openjdk-7 package fixed my compile-time errors about unsupported major.minor versions. ### 4.2 Debian Backports Debian Backports are versions of software packages that are intended for the next Debian release but are tuned to work in the current release so that users can access the latest versions of software. They are not necessarily tested as extensively as packages in the stable distribution. To enable backports in Jessie, add it to /etc/apt/sources.list and then run apt-get update. deb http://ftp.debian.org/debian jessie-backports main  To install a package from backports, use apt-get -t jessie-backports install package  ### 4.3 Uninstall programs via the command line You can search for installed packages with dpkg. dpkg --list  Pipe the output to grep if you want to filter this list: dpkg --list | grep PROGRAM_NAME  Once you find the name of the program, you can uninstall it with apt-get: sudo apt-get --purge remove PROGRAM_NAME  ## 5 File Systems ### 5.1 Renaming partitions Date 2017-02-04 Sources This section explains how to rename a partition belonging to an external USB harddrive. Currently, the harddrive is always mounted to /media/kmdouglass/0049C46E58BE73D1/. I want to change the number to something more descriptive. #### 5.1.1 Find the device and type of file system sudo mount  Look for the device corresponding to the mount point. In this case: /dev/sdb1 on /media/kmdouglass/0049C46E58BE73D1 type fuseblk (rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096,uhelper=udisks2)  To get the file system type, use sudo fdisk -l | grep /dev/sdb1. /dev/sdb1 2048 1953458175 1953456128 931.5G 7 HPFS/NTFS/exFAT  #### 5.1.2 Install the labeling program (if necessary) Since my drive is formatted as NTFS, I'll use the program ntfslabel. sudo apt-get install ntfs-3g  #### 5.1.3 Rename the partition First unmount it: sudo umount /dev/sdb1  Next, check the current label. sudo ntfslabel /dev/sdb1  When I ran the above command it returned nothing. Let's go ahead and assign a label to it then. sudo ntfslabel /dev/sdb1 kmd-backup  Unplug the drive and plug it back in. #### 5.1.4 Check the new name Try mounting the device and check the output of mount again. You should now see the name of the drive. In my case, the mount point is /media/kmdouglass/kmd-backup. ### 5.2 Finding UUID's and labels of partitions Date 2017-02-04 Sources #### 5.2.1 By UUID ls -l /dev/disk/by-uuid/  #### 5.2.2 By label ls -l /dev/disk/by-label  ### 5.3 Format a USB drive and encrypt it Date: August 2, 2017 We will use cryptsetup to perform the drive encryption. sudo apt-get install cryptsetup  First, find the USB drive label as described above and repeated here: sudo fdisk -l  I will assume for the rest of this section that the device label is /dev/sdb1. Next, ensure that the device is not mounted: sudo umount /dev/sdb1  If you are going to use the USB drive for secure purposes, you may want to start by first writing random bytes to the drive before creating the file system: sudo dd if=/dev/urandom of=/dev/sdb bs=4M oflag=direct  Note that we write the random data directly to the disk /dev/sdb, not the partition /dev/sdb1. dd is a Linux program for creating a copying files. The if option specifies the input file, in this case a special device driver for generating random data. of is the output file, in this case the Linux file driver for the USB device. BE SURE THAT YOU VERIFY THAT THIS NAME IS CORRECT. bs specifies the block size, or which is the number of bytes that are written at a time. oflag=direct bypasses the system cache and writes directly to the drive. Writing random data to the disk will likely take a while, so you can display progress like this: echo "MiB Written - Time Elapsed - Speed" && pv -tab /dev/urandom | sudo dd of=/dev/sdb1 bs=4M iflag=fullblock oflag=direct  Next, we use parted to create a partition table on the drive. We will make only one primary partition that spans the full size of the drive. sudo parted -s /dev/sdb mklabel msdos mkpart primary 0% 100%  This creates a msdos-style disk label and a single primary partition that runs from the beginning of the drive (0%) to the end (100%) on the /dev/sdb device. Now, we'll use cryptsetup to create the LUKS (Linux Unified Key System) volume on the drive. sudo cryptsetup -v luksFormat /dev/sdb1  It will ask you to verify that you may lose all data, and then to specify a password. If all goes well, you will see the Command successful. message. Open the volume. sudo cryptsetup luksOpen /dev/sdb1 MYDEVICE  This will create a device named MYDEVICE inside /dev/mapper. The next step will be to create a file system on this volume. We will use mkfs to make a new file system on the drive. mkfs is the Linux program that builds a new file system. In this example, I will make a FAT32 file system with the label my_drive (note that the options will vary with the file system you are creating): sudo mkfs.vfat -n 'my_drive' -I /dev/mapper/MYDEVICE  We can check that the encrypted partition exists using lsblk. Finally, let's go ahead and mount the drive so that we can add files to it. sudo mkdir /mnt/My_Device sudo mount /dev/mapper/MYDEVICE /mnt/My_Device  #### 5.3.1 Closing the encrypted partition To close the encrypted partition, first unmount it: sudo umount /mnt/My_Device  Next, close the LUKS container: sudo cryptsetup close MYDEVICE  ### 5.4 Transferring pictures from a digital camera Date: August 5, 2017 Some digital cameras–like my Nikon D70s–support only the Picture Transfer Protocol (PTP). This means that they cannot be mounted like a normal USB drive. To transfer images from such a device, use the gphotofs library. This uses libgphoto2, which supports the Nikon D70s. First, install it: sudo apt-get update && sudo apt-get install gphotofs  Next plugin the camera via the USB port and turn it on. Create a mount point in /media and mount the camera there: sudo mkdir /media/d70s sudo chown kmdouglass /media/d70s gphotofs /media/d70s  To unmount the camera, use fusermount -u /media/d70s. ### 5.5 SSH transfers to/from an Android device Date: August 18, 2017 Source: https://stackoverflow.com/questions/11468053/how-can-i-communicate-with-an-android-device-via-ssh I tried using media transfer protocol (MTP) to transfer files between my PC and Android without success. This led me to try SSH, which worked for basic transfers. Here's how I did it: 1. Download and install SSHDroid on the Android device. 2. Open the SSHDroid app. 3. Make note of the IP and port number. 4. On the PC, you can log in using ssh: ssh USER@IP_ADDRESS -p PORT, where USER, IP_ADDRESS, and PORT are all provided by SSHDroid. 5. Enter the password assigned by SSHDroid. By default, it will be printed to the terminal during the login attempt. Note that this will only give you access to SSHDroid's user folder on the Android device. To actually access this data, your Android needs to be rooted. To use ssh for simple file transfers, we can use scp. scp -P PORT /path/to/pc/file USER@IP_ADDRESS:/path/to/android/file  ### 5.6 CIFS I use CIFS to access my network shares at work, some of which come from Windows servers. #### 5.6.1 CIFS installation It's easy. sudo apt-get install cifs-utils #### 5.6.2 Accessing Windows shares remotely Sources First, I created a credentials file with my Windows username and password called ~/.smbcredentials. It contained the lines username=USERNAME password=PASSWORD  with the obvious substitutions. I changed the read/write credentials using chmod 600 ~/.smbcredentials. Next, I created a mount point for the network share at /mnt/LEB-Z. I then added the following line to /etc/fstab //SERVERIP/LEB /mnt/LEB-Z cifs credentials=/home/kmdouglass/.smbcredentials,iocharset=utf8,sec=ntlm,noauto 0 0  The noauto parameter ensures that the share is not mounted at startup or with the sudo mount -a command. To mount the share, I enter the command sudo mount /mnt/LEB-Z. #### 5.6.3 fstab options for mounting shares as a user The method described above will mount the CIFS share as root, which means you're user account won't be able to access the files and directories. To get around this, I modified the fstab line as such: //SERVERIP/LEB /mnt/LEB-Z cifs credentials=/home/kmdouglass/.smbcredentials,iocharset=utf8,sec=ntlm,uid=1000,gid=1000,noauto 0 0  UID and GID are user and group id numbers for the user of interest. These can be obtained with id -u username and id -g username. After mounting the share, the ownership still needs to be changed. This is done with the command sudo chown -R user:user /mnt/LEB-Z  where user is the username that belongs to the UID. ## 6 Networking ### 6.1 Find a machine's ip address/gateway/subnet/dns info Date 2017-02-04 An Internet Protocol (IP) address is a unique number that can identify each host (computers, routers, switches, etc.) on a network. When a host sends information to the IP address of a second receiving host it includes IP of origination, IP of destination and other information. Knowing the IP address of key network components such as routers, firewalls and servers, can be useful when troubleshooting network problems. Use of utilities like Ping or Trace Route can help isolate problem areas. A knowledge of relevant network topology and settings including DNS, gateway and subnet mask can also be useful when exploring network issues. Domain Name Service (DNS) numbers are IP addresses that a workstation or server uses to refer to specific servers that resolve domain names to IP addresses. A gateway IP refers to a device on a network which sends local network traffic to other networks. The subnet mask number helps to define the relationship between the host (computers, routers, switches, etc.) and the rest of the network. #### 6.1.1 Finding a machine's IP address and subnet mask Here's an example output (i.e. not from my machine) from sudo ifconfig. eth0 Link encap:Ethernet HWaddr 00:10:5A:1A:DC:65 inet addr:198.209.253.169 Bcast:208.141.109.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:18940 errors:1 dropped:0 overruns:0 frame:2 TX packets:11554 errors:0 dropped:0 overruns:0 carrier:0 collisions:2 txqueuelen:100 RX bytes:4087250 (3.8 Mb) TX bytes:2499423 (2.3 Mb) Interrupt:11 Base address:0xd000  The IP address is denoted by inet addr: and is 198.209.253.169. The mask is denoted by Mask: and in this case is 255.255.255.0. #### 6.1.2 Finding the gateway's IP address kmdouglass@kmd-laptop:~$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 wlan0


In this case, the private IP address of my router is 192.168.0.1. This is pretty standard for private networks.

#### 6.1.3 Finding the Domain Name Servers (DNS)

cat /etc/resolv.conf


### 6.2 Connecting to a hotel's network

Date 2017-02-04

To get internet access in Debian at a hotel:

First, scan for networks with sudo iwlist wlan0 scanning. If you bring down wlan0 before doing this, you can't scan.

You can also pipe this to grep ESSID, like:

sudo iwlist wlan0 scanning | grep ESSID

Bring down the interface with sudo ifdown wlan0

Next, edit /etc/network/interfaces and comment out the lines that automatically try to make wlan0 use dhcp when bringing it up. You may also have to stop network-manger using sudo service network-manager stop.

After that, set the essid to the hotel's: sudo iwconfig wlan0 essid "ESSID IN QUOTES"

Finally, request an ip with sudo dhclient wlan0.

### 6.3 Copying files using ssh

Date 2017-02-05

To copy a file from one machine to another using ssh, use the scp command.

scp /path/to/file username@a:/path/to/destination


for copying from B to A while logged into B.

scp username@b:/path/to/file /path/to/destination


for copying from B to A while logged into A.

Note that I should NOT be logged into the machine through a ssh shell.

### 6.4 Remote desktop from Debian to a Windows machine

Date 2017-04-20

Sources

rdesktop PC_IP_ADDRESS


You can change the screen size via

rdesktop -g 1280x720 PC_IP_ADDRESS


## 7 Python setup

NOTE: This section is relatively out of date as of 2017/02/04. I now use Anaconda to manage Python libraries.

### 7.1 Compiling Python 3.4

Sources

Note before compiling: the libssl-dev package should be installed for pip to work, and libsqlite3-dev should be installed for IPython History. tk8.5 and tk8.5-dev should be installed if you later want to use Tk in matplotlib. Finally, libbz2-dev should already be installed to ensure that Python has access to the bz2 headers.

I installed Python 3.4 with the following commands:

CXX="/usr/bin/g++" \./configure --prefix=/usr --enable-shared --with-system-expat --with-system-ffi --with-ensurepip=install
make


Next, run the following commands as root:

make install
chmod -v 755 /usr/lib/libpython3.4m.so
chmod -v 755 /usr/lib/libpython3.so


install -v -dm755 /usr/share/doc/python-3.4.0/html
tar --strip-components=1 --no-same-owner --no-same-permissions -C /usr/share/doc/python-3.4.0/html -xvf ../python-3.4.0-docs-html.tar.bz2


In ~/.profile, add the line PYTHONDOCS="usr/share/doc/python-3.4.0/html"; export PYTHONDOCS to the bottom of the file to set the PYTHONDOCS environment variable.

Finally, I removed /usr/bin/python and created a symbolic link to Python3.4 so that it would run as the default:

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.4 /usr/bin/python


### 7.2 Installing IPython 2.0

Sources

IPython 2.0 can be installed using pip. The command to run with Python3 is actually pip3. Use the [notebook] option if you also want to install the IPython notebook as well.

sudo pip3 install ipython[notebook]


When I ran IPython the first time, I received the following messages:

WARNING: IPython History requires SQLite, your history will not be saved
WARNING: The auto-indent feature requires the readline library


I fixed the readline errors by running sudo pip3 install readline. However, I had to rebuild Python3 with the package libsqlite3-dev installed to get rid of the sqlite error.

#### 7.2.1 IPython Notebook

The IPython notebook required that I install libzmq with apt-get and pyzmq with pip3.

#### 7.2.2 Fixing indentation errors

Source

I've been receiving some indentation errors in IPython. These are more-or-less fixed by turning off autoindent in IPython. To do this, I first created the default IPython configuration files by running

ipython profile create


Following this, I edited ~/.ipython/profile_default/ipython_config.py. I uncommented the line about autoindent and set the argument to False. This fixed the indentation errors.

### 7.3 Installing Numpy 1.8.1, matplotlib 1.3.1, scipy 0.14, and Pillow 2.4.0

Numpy 1.8.1 can be installed with pip3. Before doing so, I first ATLAS with sudo apt-get install libatlas-base-dev. Next, I downloaded the Numpy source and unzipped it.

matplotlib and Pillow are also easily installed with pip3. Before installing scipy, be sure that there is a Fortran compiler on your system, such as gfortran.

### 7.4 Multiple IPython prompts at startup

The reasons for the multiple prompts appearing the start of Ipython in emacs is given in this disccusion.

### 7.5 Getting Tk and Latex support in Python

The first time I built Python, I did not have tk8.5 or tk8.5-dev installed. This prevented me from creating plots with matplotlib. So, I recompiled Python after installing these packages.

I believe that I will also have to rebuild matplotlib in the future if I want Latex support.

### 7.6 Installing Jedi

Sources

Jedi is a Python autocomplete tool for emacs that I had some trouble installing at first. In the end, I think the problem was with an old version on the Maramelade emacs package server.

I first installed the following Python packages using pip3 like normal: sudo pip3 install <PACKAGE>.

• jedi
• epc
• virtualenv
• argparse (I'm not sure if this one's necessary; I saw it on a forum when I was troubleh shooting.)

This only installs the Jedi library for Python and a few other Python modules. To install Jedi for emacs I used el-get since the version it installed was up-to-date. (When I tried to install from the Marmalade repo using package.el, the repository version was 0.1.2, but the current version of jedi is 0.2.0.) To install el-get, I added the following lines to init.el:

; Standard el-get setup

(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.github.com/dimitri/el-get/master/el-get-install.el")
(goto-char (point-max))
(eval-print-last-sexp)))

(el-get 'sync)


Next, I ran init.el using M-x load-file. I watched the Messages buffer during this time to watch for when the el-get install finished (it takes a few minutes). After it had installed and I restarted emacs for good measure, I ran the command M-x el-get-install RET jedi RET. Again, I waited until it finished, then ran the command M-x jedi:install-server RET. This command is missing in 0.1.2.

Finally, I added the following lines to init.el, restarted emacs, and had a working jedi install.

;; Standard Jedi.el setting
(setq jedi:complete-on-dot t)


## 8 Org-mode configuration

### 8.1 Publish to LaTeX with references

Sources

I found a recent and excellent post to the TeX Stack Exchange concerning getting org-mode to faithfully create bibliographies in pdf's published from LaTeX. This task has been notoriously difficult for me in the past.

In brief, I installed the texlive-bibtex-extra and latexmk packages from the Debian repositories to assemble my tools. Next, I used the minimal example from the Stack Exchange link and modified it slightly:

#+LATEX_HEADER: \usepackage{fullpage}

#+TITLE: Telomere Master Notes
#+AUTHOR: Kyle M. Douglass
#+DATE: \today

Telomeres consist of DNA tandem repeat sequences, their associated
binding proteins, and a non-coding RNA transcript. They are located at
the end of chromosomes and address two important problems in
eukaryotes: the end-replication problem and the end-protection
problem. A nice summary is provided in \cite{sfeir-jcellsci-2012}.

\printbibliography


Finally, I changed my original init.el file by modifying org-latex-pdf-process to the following:

(setq org-latex-pdf-process
'("latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf -bibtex -f %f"))


This was changed from what I had used in the past:

(setq org-latex-to-pdf-process '("pdflatex -interaction nonstopmode %b"
"/usr/bin/bibtex %b"
"pdflatex -interaction nonstopmode %b"
"pdflatex -interaction nonstopmode %b"))


Now, publishing to pdf with Latex and including citations works well.

## 9 Booting from a bootloader on a USB stick

I ran into some issues installing Debian on my work computer, which, I suspect, was due to a crazy partition scheme. I inherited this computer from someone else and can't change the harddrive layout, so I've been attempting to work around it.

Luckily, there was a 500 GB chunk of free space at the end of one hard drive, so I decided to install Debian Wheezy there. I booted into a Live CD and ran the installer. Unfortunately, the install hung while searching for the other operating systems on the computer to setup Grub. So after waiting an hour, I manually restarted the computer.

Fortunately, the MBR was untouched so the computer started as if nothing had ever happened to it. Windows also worked fine. I could also see what appeared to be the full file system for Debian installed at the parition I put it in. Rather than risk botching the MBR, I thought I would try installing GRUB onto a USB stick and using it to boot to the new installation.

### 9.1 Installing GRUB onto a USB stick

Sources

I first booted into Linux with my Debian Live CD. After inserting a spare USB stick, I loaded a terminal window and typed sudo su to get a root prompt. Next, I checked which device the USB stick was labeled as by inspecting the output of fdisk -l. I mounted the stick with mkdir /mnt/USB && mount /dev/sdX /mnt/USB. (Replace 'X' with the device label, usually a letter and a number).

Next, I installed GRUB to the MBR of this USB stick by typing this important command:

grub-install --force --no-floppy --boot-directory=/mnt/USB/boot /dev/sdX


(Again, X should be replaced with the appropriate device label.) This installed GRUB to the USB for what would be the live system. The next step involves configuring GRUB to boot the stranded Linux install.

### 9.2 Configuring GRUB on the USB stick to work with your machine

Sources

After installing GRUB to the USB stick, it's necessary to change /boot/grub/grub.cfg on the USB to reflect your machine's hardware. This is made easy with the command grub-update and a Live CD.

After booting into the live CD environment, I mounted the stranded partition to /mnt/linux. Next, I loaded some necessary directories from the running live instances into the newly mounted partition.

sudo mount --bind /dev /mnt/linux/dev
sudo mount --bind /sys /mnt/linux/sys
sudo mount --bind /proc /mnt/linux/proc


Next I chroot'ed into the partition with sudo chroot /mnt/linux. I next ran

sudo update-grub


which generated the grub.cfg file on the current partition. I copied this to /boot/grub in my USB stick, rebooted the computer, and successfully loaded the stranded partition from the bootloader on the USB stick.

### 9.3 GRUB troubleshooting

#### 9.3.1 GRUB installation hangs when making device.map

When I recently upgraded from Debian Wheezy to Jessie, I encountered a lot of difficulty with GRUB hanging during its installation. This forced me to rescure my partition with a LiveCD, which wasn't easy because even during rescue the GRUB installation would fail.

Typically, it would hang just after setting up memtest86-multiboot. The problem, I discovered, lay with probing other hard drives for different operating systems. Since I no longer needed my Windows installation (I used a virtual machine instead), I disabled the OS prober by adding the following line to the top of /etc/default/grub:

GRUB_DISABLE_OS_PROBER=true


I then killed all GRUB processes and ran sudo update-grub to configure GRUB on my system without the Windows partitions.