пятница, 6 июля 2012 г.

Samba File Server

One of the most common ways to network Ubuntu and Windows computers is to configure Samba as a File Server. This section covers setting up a Samba server to share files with Windows clients.

The server will be configured to share files with any client on the network without prompting for a password. If your environment requires stricter Access Controls see Securing a Samba File and Print Server


The first step is to install the samba package. From a terminal prompt enter:
sudo apt-get install samba-server
sudo gedit /etc/samba/smb.conf
That's all there is to it; you are now ready to configure Samba to share files.


The main Samba configuration file is located in /etc/samba/smb.conf. The default configuration file has a significant amount of comments in order to document various configuration directives.
Not all the available options are included in the default configuration file. See the smb.conf man page or the Samba HOWTO Collectionfor more details.
  1. First, edit the following key/value pairs in the [global] section of /etc/samba/smb.conf:
       workgroup = EXAMPLE
       security = user
    The security parameter is farther down in the [global] section, and is commented by default. Also, change EXAMPLE to better match your environment.
  2. Create a new section at the bottom of the file, or uncomment one of the examples, for the directory to be shared:
        comment = Ubuntu File Server Share
        path = /srv/samba/share
        browsable = yes
        guest ok = yes
        read only = no
        create mask = 0755
    • comment: a short description of the share. Adjust to fit your needs.
    • path: the path to the directory to share.
      This example uses /srv/samba/sharename because, according to the Filesystem Hierarchy Standard (FHS)/srv is where site-specific data should be served. Technically Samba shares can be placed anywhere on the filesystem as long as the permissions are correct, but adhering to standards is recommended.
    • browsable: enables Windows clients to browse the shared directory using Windows Explorer.
    • guest ok: allows clients to connect to the share without supplying a password.
    • read only: determines if the share is read only or if write privileges are granted. Write privileges are allowed only when the value is no, as is seen in this example. If the value is yes, then access to the share is read only.
    • create mask: determines the permissions new files will have when created.
  3. Now that Samba is configured, the directory needs to be created and the permissions changed. From a terminal enter:
    sudo mkdir -p /srv/samba/share
    sudo chown nobody.nogroup /srv/samba/share/
    The -p switch tells mkdir to create the entire directory tree if it doesn't exist.
  4. Finally, restart the samba services to enable the new configuration:
    sudo restart smbd
    sudo restart nmbd
Once again, the above configuration gives all access to any client on the local network. For a more secure configuration see Securing a Samba File and Print Server.
From a Windows client you should now be able to browse to the Ubuntu file server and see the shared directory. To check that everything is working try creating a directory from Windows.
To create additional shares simply create new [dir] sections in /etc/samba/smb.conf, and restart Samba. Just make sure that the directory you want to share actually exists and the permissions are correct.
The file share named "[share]" and the path /srv/samba/share are just examples. Adjust the share and path names to fit your environment. It is a good idea to name a share after a directory on the file system. Another example would be a share name of [qa] with a path of /srv/samba/qa.


Set / Change / Reset the MySQL root password on Ubuntu Linux

Tested on
- Ubuntu Linux 7.10 Gutsy Gibbon and MySQL 5.0.45. (2007-10-21)
- Ubuntu Linux 6.06 Dapper Drake and MySQL 4.1.15.

Set / change / reset the MySQL root password on Ubuntu Linux. Enter the following lines in your terminal.
  1. Stop the MySQL Server.
    sudo /etc/init.d/mysql stop

  2. Start the mysqld configuration.
    sudo mysqld --skip-grant-tables &

  3. Login to MySQL as root.
    mysql -u root mysql

  4. Replace YOURNEWPASSWORD with your new password!
Note: This method is not regarded as the securest way of resetting the password. However it works.

вторник, 3 июля 2012 г.

How to Reset USB Device in Linux

USB devices are anywhere nowadays, even many embedded devices replace the traditional serial devices with usb devices. However, I experienced that USB devices hang from time to time. In most cases, a manual unplug and replug will solve the issue. Actually, usb reset can simulate the unplug and replug operation.
First, get the device path for your usb device. Enter the command lsusb will give you something similar as below,

Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 002: ID 04b3:310c IBM Corp. Wheel Mouse
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 002: ID 0a5c:2145 Broadcom Corp.
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Use the IBM Wheel Mouse as an example, the device node for it is /dev/bus/usb/006/002, where 006 is the bus number, and 002 is the device number.
Second, apply ioctl operation to reset the device. This is done in C code,

#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
void main(int argc, char **argv)
 const char *filename;
 int fd;
 filename = argv[1];
 fd = open(filename, O_WRONLY);
 ioctl(fd, USBDEVFS_RESET, 0);
Save the code above as reset.c, then compile the code using
gcc -o reset reset.c
This will produce the a binary named reset. Again, using the wheel mouse as an example, execute the following commands,
sudo ./reset /dev/bus/usb/006/002
You can take a look at the message by,
tail -f /var/log/messages
On my Ubuntu desktop, the last line reads,
May 4 16:09:17 roman10 kernel: [ 1663.013118] usb 6-2:
reset low speed USB device using uhci_hcd and address 2
This reset operation is effectively the same as you unplug and replug a usb device.
For another method of reset usb using libusb, please refer here


alternative method

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>

#include <linux/usbdevice_fs.h>

int main(int argc, char **argv)
 const char *filename;
 int fd;
 int rc;

 if (argc != 2) {
  fprintf(stderr, "Usage: usbreset device-filename\n");
  return 1;
 filename = argv[1];

 fd = open(filename, O_WRONLY);
 if (fd < 0) {
  perror("Error opening output file");
  return 1;

 printf("Resetting USB device %s\n", filename);
 rc = ioctl(fd, USBDEVFS_RESET, 0);
 if (rc < 0) {
  perror("Error in ioctl");
  return 1;
 printf("Reset successful\n");

 return 0;

$ cc usbreset.c -o usbreset
$ lsusb
Bus 002 Device 003: ID 0fe9:9010 DVICO

$ chmod +x usbreset
$ sudo ./usbreset /dev/bus/usb/002/003


понедельник, 2 июля 2012 г.

Installing Gnome 3

Installing Gnome 3

Before we continue, it is worth mentioning that there is a gnome package in the default Ubuntu repository for Gnome, however from what I understood from several articles this version is outdated and does not include all the beauty that is included in the latest Gnome 3 release. So you may want to skip installing the default package from the repository.
The good news is that installing the latest Gnome 3 on Ubuntu 12.04 is extremely easy. Just copy-paste the following lines for the latest release from the Gnome team into a terminal (type Ctrl-Alt T to open a terminal window):

sudo add-apt-repository ppa:gnome3-team/gnome3
sudo apt-get update
sudo apt-get install gnome-shell

Gnome 3 Shell Extensions

One of the great new features of Gnome 3 is the possibility to add “shell extensions”. These are small user interface elements which can improve the overall user experience.

To install a shell extension visit the Gnome Extensions website with your browser (the default Firefox works fine for this) and install extensions by switching the “ON/OFF” button to “ON” (you can find these buttons on the individual extension pages, in the left upper corner).
You may also want to consider installing the Gnome Tweak Tool which will give you greater control over your shell extensions and several other Gnome settings. You can install this tool directly from the Ubuntu Software Repository, or by copy-pasting the following lines into a terminal:
sudo apt-get install gnome-tweak-toolYou can now find this tweak tool by searching for “Advanced Settings” in your applications or in System Tools menu.

Recommended Shell Extensions

Experiment and try out some shell extensions. Personally I recommend to at least try out activating/installing the following shell extensions:
Alternatively, if you prefer to install a small collection of popular shell extensions in one go (including most of the listed above) you can copy-paste the following lines in a terminal:

sudo add-apt-repository ppa:ricotz/testing
sudo apt-get update
sudo apt-get install gnome-shell-extensions-common
And once you have finished installing extensions, visit the Installed Extensions page on the Gnome Extensions website or the “Shell Extensions” option in the Gnome Tweak Tool. There you will be able to see, enable/disable and customize settings of the individual extensions from the collection.
An important note about using Gnome shell extensions: Unfortunately any installed shell extension will not automatically be updated when newer versions are released. You will need to manually remove and reinstall any shell extension which conflicts with future Gnome 3 or Ubuntu updates. This is something the Gnome team is aware of and (I hope) is working on fixing.

Remove an application

apt-get is the command-line tool for handling packages. It is used for adding / removing / updating packages.

Uninstall / Delete / Remove Package

Just use the following syntax:
sudo apt-get remove {package-name}
For example remove package called mplayer, enter:

$ sudo apt-get remove mplayer

Remove package called lighttpd along with all configuration files, enter:

$ sudo apt-get --purge remove lighttpd

To list all installed package, enter:\

dpkg --list
dpkg --list | less
dpkg --list | grep -i 'http'

sudo apt-get --purge remove libreoffice-core

воскресенье, 1 июля 2012 г.