Tag Archives: ubuntu

Automatically Mount A USB Drive In Ubuntu Server

USB drives can be easily and automatically mounted on Ubuntu Server with the help of USBmount which is available from the Ubuntu and Debian repositories. Fortunately, USBmount requires little configuration in order to work. The following was tested in Debian 7 Wheezy and Ubuntu 13.04.

Installation and Configuration

Make sure you run apt-get update/upgrade before starting the tutorial.

sudo apt-get update
sudo apt-get upgrade

Now install USBmount from the repositories.

sudo apt-get install usbmount

USBmount mounts all USB drives in /media/usb*.

Now plug a USB drive and wait for it to be detected and mounted. As long as the host OS supports the File System it should be mounted.

To verify whether the USB drive was mounted correctly you can use df -h to view all available drives and their respective mount points. My 4GB USB drive is accessible from the /media/usb0 mount point.

user@debian:~$ df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   49G   18G   29G  38% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   100M  432K  100M   1% /run
/dev/disk/by-uuid/af874479-b4ee-4d83-a3da-d2fdb48511ea   49G   18G   29G  38% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   404M     0  404M   0% /run/shm
/dev/sdb1                                               138G   14G  118G  11% /media/hdd1
/dev/sdc1                                               3.8G  6.6M  3.8G   1% /media/usb0

To un-mount a drive you can use umount.

sudo umount /media/usb0

Conclusion

USBmount is quite handy for mounting USB drives with no effort.

502 Bad Gateway – Nginx and PHP-FPM

Nginx 502 Bad Gateway cost me more time than the actual Ubuntu + PHP-FPM + MySQL installation I was working on. In my case the 502 Bad Gateway error on my installation was the result of a parameter mismatch between /etc/ningx/sites-available/default and /etc/php5/fpm/pool.d/www.conf.

In order to solve the 502 Bad Gateway problem edit the Nginx file /etc/ningx/sites-available/default.

nano /etc/ningx/sites-available/default

And look for the commented line # fastcgi_pass unix:/var/run/php5-fpm.sock; and uncomment the line.

fastcgi_pass unix:/var/run/php5-fpm.sock;

You location ~ .php$ { section should look similar to mine.

 location ~ .php$ {
                fastcgi_split_path_info ^(.+.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

The final two steps are to restart Nginx and PHP-FPM.

sudo service nginx restart
sudo service php5-fpm restart

Now you have a working installation like it should have been from the beginning.

Increase Console Resolution In Ubuntu

Higher resolution means more text in the same window this especially applies to the console. The following was tested in Debian 7 Wheezy and Ubuntu 13.04. With Grub 2 with can easily increase the resolution by making a few changes.

Console Resolution

Open and edit the grub file.

nano /etc/default/grub

Search for the following line and uncomment “#GRUB_GFXMODE=640“, modify it to include a higher resolution such as 1440×900. Also add the line “GRUB_GFXPAYLOAD_LINUX=keep“.

GRUB_GFXMODE=1440X900
GRUB_GFXPAYLOAD_LINUX=keep

The lines above should be what increases the console resolution.

Now update Grub.

sudo update-grub

And restart the system.

sudo shutdown -r now

Now you should be able to make better use of your monitor resolution.

HTOP 1440x900

Passwd: Authentication token manipulation error – Ubuntu

You probably encountered this error while trying to reset the password on a Ubuntu system.

root@u13-04:~# passwd nyuser

Enter new UNIX password:
Retype new UNIX password:
passwd: Authentication token manipulation error
passwd: password unchanged

This is the result of trying to work on a file system while mounted as read-only. The solution is a simple one. Before making changes to the users password mount the filesystem as read-write which allows for the necessary changes to be made.

mount -o rw,remount /

Now try to change the users passwords again.

root@u13-04:~# passwd nyuser

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Can Not Add SSH Key To Ubuntu

4/17/16 – Fixed formatting.

I wanted to add an SSH key to a new minimal Debian VM install, but attempting to add the key resulted in a No such file or directory error.

sudo cat id_rsa.pub >> .ssh/authorized_keys
cat: id_rsa.pub: No such file or directory

The error was the result of the non-existent authorized_keys file which is where SSH key happens to be stored.

If we look inside the ~/.ssh directory you will notice the missing authorized_keys file.

ls ~/.ssh
known_hosts

To be able to store the SSH key create the missing authorized_keys in the right location and with the right permission.

Move to the directory where key files are stored for the user.

cd ~/.ssh

Create necessary file.

touch authorized_keys

Assign permission to file.

chmod 600 authorized_keys

Copy SSH key to authorized_keys file.

cat id_rsa.pub >> .ssh/authorized_keys

Optional, but I recommend removing the key since it’s no longer needed.

rm id_rsa.pub

Restart the service.

sudo service ssh restart

Where’s My Traceroute in Ubuntu

By default if you try to use the traceroute command in Ubuntu it will suggest installing the application since there is no application by such name installed.


user@bicerin:~$ traceroute
The program 'traceroute' can be found in the following packages:
* inetutils-traceroute
* traceroute
Try: sudo apt-get install

While you could apt-get install traceroute your way out of it, you could instead use the included mtr application.

http://manpages.ubuntu.com/manpages/gutsy/man8/mtr.8.html

mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.

I like the way mtr presents the output instead of the normal traceroute applications, mtr constantly pings the address in a live manner and watch the output update according to network conditions.


user@bicerin:~$ mtr linhost.info

Host Loss% Snt Last Avg Best Wrst StDev
1. OpenWrt.lan 0.0% 3 0.5 0.5 0.4 0.5 0.0
2. ???
3. te-9-2-ur01.fourhills.nm.albuq.comcast.net 0.0% 2 9.3 8.9 8.5 9.3 0.5
4. te-4-2-ar01.albuquerque.nm.albuq.comcast.net 0.0% 2 8.8 9.2 8.8 9.6 0.5
5. te-0-0-0-8-cr01.denverqwest.co.ibone.comcast.net 0.0% 2 18.0 23.1 18.0 28.3 7.2
6. he-3-12-0-0-cr01.denver.co.ibone.comcast.net 0.0% 2 21.2 21.0 20.9 21.2 0.2
7. xe-0-0-0.bbr01.cf01.den01.networklayer.com 0.0% 2 17.3 17.2 17.0 17.3 0.2
8. ae12.bbr02.eq01.dal03.networklayer.com 0.0% 2 31.8 33.0 31.8 34.2 1.7
9. po32.dsr01.dllstx3.networklayer.com 0.0% 2 31.6 31.6 31.6 31.7 0.1
10. po31.dsr01.dllstx2.networklayer.com 0.0% 2 31.9 32.4 31.9 33.0 0.8
11. po1.car14.dllstx6.networklayer.com 0.0% 2 34.8 35.1 34.8 35.3 0.4
12. gator524.hostgator.com 0.0% 2 31.9 32.8 31.9 33.7 1.3

I didn’t know about mtr which is why I decided to create this post as a reminder.

Install Webmin on Ubuntu 12.04

Note: This post assumes a web server is already installed.
Note: This post assumes you have administrative rights on the system.

Like always you should update and upgrade the installation.

sudo apt-get update

sudo apt-get upgrade

Webmin

Download Webmin

Visit webmin.com/download.html and download the .deb version of Webmin.

cd /tmp

wget http://prdownloads.sourceforge.net/webadmin/webmin_1.590_all.deb

Installation

Now that we have the package we can install it.

sudo dpkg -i webmin_1.590_all.deb

Actually dpkg will not be able to install Webmin because of some missing dependencies. This is why we need an extra step which will fetch the missing dependencies for us.

sudo apt-get install -f

Now you can log-in to the newly installed Webmin interface by going to the following address. Just add the IP address of the server.

https://server_ip_address:10000

Remember the log-in credentials for Webmin are the username and password you used to log in to the server.

Webmin login

Conclusion and Links

Comments and corrections are always appreciated.

Webmin Home Page http://www.webmin.com

Ubuntu: How to Create and Open Zip Files from the Command Line

If you have an Ubuntu/Debian server installation and need to open or create Zip file then you need to install the necessary packages to work with Zip files. Fortunately, we can easily add support for Zip to our installation by installing two packages(Zip, Unzip) both available from the repositories.

Note: This post assumes you have the ability to install packages, root or sudo access.

Creating a Zip Archive

Install Zip from the repositories.

# apt-get install zip

The entire process is quite simple to understand.

# zip -r new-file-name.zip directory-to-compress/
  • zip – This is the name of the application we will be using to compress
  • -r – Short for Recursive, only use this option is you are creating a compressed archived from a directory
  • new-file-name.zip – Name of the resulting compressed archive, the naming is up to you
  • directory-to-compress/ – Name of the directory we are about to compress

It is possible to add more than one directory in to the same archive.

# zip -r new-file-name.zip directory-1/ directory-2/

But, what if I only need to compress a single file. Similar process except we don’t need to use the -r(recurse) option.

# zip report.zip LitenDuplicateReport.csv

Opening a Zip archive

Opening or extracting the contents from a compressed archive is handled not by the Zip package but by a second package called Unzip.

# apt-get install unzip

With Unzip you have two options as to how the contents will be extracted, either you can extract the contents of the compressed archive to a directory or simply extract the contents to the current directory.

# unzip nc111nt.zip -d netcat/
  • unzip – Tool that will extract contents from Zip compressed archive
  • nc111nt.zip – Name of the archive we are extracting from
  • -d – Short for destination
  • netcat – Unzip will create a new directory called netcat where the contents will be extracted to

Or you can extract the contents of the archive to the current directory you are in.

# unzip nc111nt.zip

Conclusion

All you need is two packages and your installation will be able to work with Zip archives. I know Ubuntu/Debian have support for Gzip but if you work with Windows users and need to share files with them then Zip might be the only way to go.

How To Install MiniDLNA On Ubuntu

MiniDLNA is a lightweight and simple to configure DLNA server for Linux, I say simple because for this tutorial we only need to edit a single configuration file. while you can always change more settings, this tutorial will only cover the basics needed to have a working server.

MiniDLNA is server software with the aim of being fully compliant with DLNA/UPnP clients.

Preparations

Before we can install MiniDLNA make sure the installation is up to date.

sudo apt-get update
sudo apt-get upgrade

Installation

MiniDLNA is available in the Ubuntu repositories, why is why we can install the package with the help of apt-get.

sudo apt-get install minidlna

For this tutorial I will be using an Ubuntu 12.04 64-Bit installation. Also, you will need access to root.

Configuration

We need to edit the MiniDLNA configuration file.

sudo nano /etc/minidlna.conf

And uncomment and change the following settings.

#network_interface=eth0
#media_dir=/opt
#friendly_name=My DLNA Server

After making the changes your configuration should look somewhat similar to mine, make changes as necessary.

network_interface=eth0
media_dir=/usr/local/media
friendly_name=Multimedia Server

Let me explain the changes.

network_interface=eth0 – This is the network interface where all the content will be served to the clients.
media_dir=/usr/local/media – I’ve decided to store all my media files in the /usr directory, you can change the path according to your needs.
friendly_name=Multimedia – This is the name by which all the clients will recognize the server.

Restart the service.

sudo service minidlna restart

And your MiniDLNA Server is configured to serve your media files. Now go over to the client and attempt to connect. In my case the client is an Xbox 360.

xbox-dlna-0

BTW: If your client is an Xbox 360 you may have to use a transcoder like Handbrake to transcode all your files to an Xbox 360 friendly video file, Otherwise MiniDLNA will serve the files but they will appear as unvailable to the clients.

xbox-dlna-1

Optional

In the configuration above I only specified a single directory for media files, but if you wish to add more directories all you have to do is add another line to the configuration like this one:

media_dir=/usr/local/media_video

Links

MiniDLNA home page