пятница, 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

Installation

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.

Configuration

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:
    [share]
        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.

Resources

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!
    UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
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);
 close(fd);
 return;
}
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");

 close(fd);
 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 г.

How do I create a symbolic link?


ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT]
For example:
ln -s /usr/local/apache/logs ./logs
This points a symbolic link "./logs" to "/usr/local/apache/logs"

суббота, 30 июня 2012 г.

Installing LAMP On Ubuntu


Installing LAMP On Ubuntu

In this guide I will show you how to install a LAMP system. LAMP stands for Linux, Apache, MySQL, PHP. The guide is intended to help those who have very little knowlegde of using Linux.

Alternative method

sudo apt-get install tasksel

sudo tasksel


Install Apache

To start off we will install Apache.
1. Open up the Terminal (Applications > Accessories > Terminal).
2. Copy/Paste the following line of code into Terminal and then press enter:
sudo apt-get install apache2
3. The Terminal will then ask you for you're password, type it and then press enter.

Testing Apache

To make sure everything installed correctly we will now test Apache to ensure it is working properly.
1. Open up any web browser and then enter the following into the web address:
http://localhost/
You should see a folder entitled apache2-default/. Open it and you will see a message saying "It works!" , congrats to you!
echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn


sudo service apache2 reload

Install PHP

In this part we will install PHP 5.
Step 1. Again open up the Terminal (Applications > Accessories > Terminal).
Step 2. Copy/Paste the following line into Terminal and press enter:
sudo apt-get install php5 libapache2-mod-php5
Step 3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code in Terminal to do this:
sudo /etc/init.d/apache2 restart

Test PHP

To ensure there are no issues with PHP let's give it a quick test run.
Step 1. In the terminal copy/paste the following line:
sudo gedit /var/www/testphp.php
This will open up a file called phptest.php.
Step 2. Copy/Paste this line into the phptest file:
<?php phpinfo(); ?>
Step 3. Save and close the file.
Step 4. Now open you're web browser and type the following into the web address:
http://localhost/testphp.php
The page should look like this:

Congrats you have now installed both Apache and PHP!

Install MySQL

To finish this guide up we will install MySQL. (Note - Out of Apache and PHP, MySQL is the most difficult to set up. I will provide some great resources for anyone having trouble at the end of this guide.)
Step 1. Once again open up the amazing Terminal and then copy/paste this line:
sudo apt-get install mysql-server

Enter the password you want to use for MySQL, Do not leave it blank . You'll be prompted a second time to confirm your password.


How to remove it totally use this:


sudo apt-get remove mysql-common mysql-server
sudo apt-get --purge remove 


Step 2 (optional). In order for other computers on your network to view the server you have created, you must first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf file.
sudo gedit /etc/mysql/my.cnf
Change the line
bind-address = 127.0.0.1
And change the 127.0.0.1 to your IP address.
Step 3. (optional) This is where things may start to get tricky. Begin by typing the following into Terminal:
mysql -u root
Following that copy/paste this line:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');
(Make sure to change yourpassword to a password of your choice.)
Step 4. We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste the following line into Terminal:
sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:
sudo gedit /etc/php5/apache2/php.ini
Now we are going to have to uncomment the following line by taking out the semicolon (;).
Change this line:
;extension=mysql.so
To look like this:
extension=mysql.so
Now just restart Apache and you are all set!
sudo /etc/init.d/apache2 restart

Known Issues:

Symolic link to  var/www folder is not working

Forbidden

You don't have permission to access *** on this server.

Apache/2.2.22 (Ubuntu) Server at localhost Port 80



sometimes its happening if:
your source folder are on ntfs file system, or if you using already created folder, witch have different chmod, probably from previous owner or installation. I sorted out this problem by creating new folder in ext4 file system and made symbolic link to /var/www folder.


The End

Quick note to anyone who encountered problems with setting up the MySQL password, please refer to this page: MysqlPasswordReset
I applaud everyone who has taken the time to read this guide. This guide is also my first ever so I would love to hear back from the public on what you guys think! Just don't be too harsh. ;)
If you have questions about installing any part of LAMP just drop them in the comment box and I will do my best to help you out.