Notes on Ubuntu

Notes on Ubuntu

Adding, Removing, and Updating Software

Ubuntu Repositories and Components

Ubuntu repositories contain four basic components: main, restricted, universe, multiverse.

Enabling Additional Repository Components

By default, only the main and restricted components of the Ubuntu repositories are enabled. /etc/apt/sources.list is the file that all of the package installation and management utilities consult when looking for new and updated software.

The /etc/apt/sources.list entries for this repository are the following:

deb dapper main

deb-src dapper main

We can add other repositorie here. Once you are done adding the repositories, run this command: apt-get update

Or we can use the Software Sources Tool: select the System > Administration > Software Sources

Exploring Your System Using dpkg

dpkg -l listing the Packages that are Installed on Your System

dpkg -l ‘emacs*’

aptitude search emacs

apt-cache search emacs

Listing Information About a Package aptitude show xemacs21

Listing the Contents of a Package dpkg -L emacs21

Determining What Package Provides an Existing File

dpkg --search /usr/bin/ar

dpkg --search `which ar`

dlocate -S /usr/bin/emacs

(dlocate utility is not installed on Ubuntu systems by default.)

Determining What Package Provides a Missing File

apt-file search

Using apt-get to Add and Remove Software

apt-get [ -hvs ] [ -o=config string ] [ -c=file ] { update | upgrade | dselect-upgrade | install pkg ... | remove pkg ... | source pkg ... | build-dep pkg ... | check | clean | autoclean }

Upgrading Your System Using apt-get upgrade

The apt-get upgrade command searches all of the repositories in your /etc/apt/sources.list file for new versions of packages that are currently installed on your system, and downloads and installs those new versions.

Smart System Upgrades Using apt-get dist-upgrade

apt-get dist-upgrade will do its best to handle any new package requirements or the removal of any existing packages that mandated in order to install the latest versions of all of the software on your system.

Retrieving Package Source Code Using apt-get source

apt-get source mythtv

Satisfying Build Dependencies Using apt-get build-dep

apt-get build-dep mythtv

Using aptitude to Add and Remove Software

Using Synaptic to Add and Remove Software

System > Administration > Synaptic Package Manager

Using the Ubuntu Update Manager

System > Administration > Update Manager

Converting Packages from Other Package Formats

The alien application can convert packages to and from the following formats: DEB, RPM,PKG, LSB, SLP, TGZ.

Using alien to convert from one package format to another is easy. The alien application provides options such as --to-deb, --to-lsb, --to-rpm, and --to-tgz to specify the target output format.

alien --scripts --to-deb AdobeReader_enu-7.0.0-2.i386.rpm

Keeping your System Lean, Mean, and Pristine

deborphan and debfoster

deborphan utility produces a list of packages that are not used or referred to by any system package on your system, while the debfoster package builds its own database of which packages are required, tries to be smart about things that you may not need, and also asks lots of questions the first time you run it.

deborphan | xargs apt-get remove --purge -y

Connecting to Other Systems


Use Synaptic Package Manager to install the OpenSSH server.

apt-get install openssh-server

OpenSSH allows different services to be passed through the connection. These services include interactive shell sessions (ssh), remote command execution (ssh), file copying (scp), FTP services (sftp), X11 client/server connections, and TCP/IP port tunneling.


/etc/ssh: Global Files

~/.ssh: User Files


Two files list the hosts the local system has connected to and positively identified: ~/.ssh/known_hosts (user) and /etc/ssh/ssh_known_hosts (global).

ssh [options] [user@]host [command]

ssh user@host ls memos

ssh user@host cat memos/memo.draft | diff –

After you configure the OpenSSH server, call the ssh init script to restart the sshd daemon: sudo /etc/init.d/sshd reload

SSH login without password

Target: automatic login from host A / user a to Host B / user b

On machine A: do the following steps:

1. Generate a pair of authentication keys

ssh-keygen -t rsa

2. Create a directory ~/.ssh as user b on B

ssh b@B mkdir -p .ssh

3. Append a's new public key to b@B:.ssh/authorized_keys

cat .ssh/ | ssh b@B 'cat >> .ssh/authorized_keys'

Connecting to Other Systems Using VNC

VNC is a protocol that allows a desktop to be viewed and controlled remotely over the Internet. To use VNC, you need to run a VNC server on the computer sharing a destkop, and a VNC client on the computer accessing the shared desktop.

Getting VNC Client and Server Software for Your Other Platforms

The vino VNC server for Ubuntu

Vino is the default VNC server in Ubuntu to share your existing desktop with other users. To make sure that the vino VNC server is enabled for you, select the System ➪ Preferences ➪ Remote Desktop menu item.

Setup vnc4server


apt-get install vnc4server xinetd

Set the VNC passwd

vncpasswd /root/.vncpasswd

Reinitialize the service

sudo /etc/init.d/xinetd stop

sudo killall Xvnc

sudo /etc/init.d/xinetd start

Test the connection

vncviewer localhost:1

VNC Clients and Servers for Windows

TightVNC and RealVNC.

TightVNC is a small, highly optimized VNC client and server. TightVNC makes efficient use of network bandwidth through some clever tricks using JPEG compression for the display and differentiating between local cursor movement and cursor movement that needs to be communicated back to the VNC server. TightVNC also provides security features, including automatic SSH tunneling for security purposes.

TightVNC can be downloaded from or from their SourceForge site at

Using vncviewer host:display



Installing vsftpd sudo apt-get install vsftpd

The configuration file for vsftpd is located in /etc/vsftpd.conf

Change its configuration as following












ftpd_banner=Welcome to blah FTP service.






sudo /etc/init.d/vsftpd start | stop | restart



apt-get install firestarter

User need enable the "universe" repository in the /etc/apt/sources.list file or in synaptic under Settings->Repositories.

After Installation, Select via System > Administration > Firestarter

Inbound Policy

The default inbound policy is to block all inbound connections except connections that are responding to outbound connections.

Allow connections from host Specifies a host or network that firestarter accepts any incoming connection from. Make sure you trust this system or network completely.

Allow service Specifies a service (port) that firestarter accepts inbound connections on. You can specify that firestarter accept inbound connections on the specified port from anyone, all clients, or a specific host or network on the Internet.

Forward service Specifies a service (port) that firestarter will accept inbound connections on. The firestarter firewall forwards these connections to the client you specify on the port you specify. Forwarding a service is appropriate if you are running a server on a client system and want systems on the Internet to be able to connect to the server.

Outbound Policy

Permissive by default, blacklist traffic

Restrictive by default, whitelist traffic



Server: sudo apt-get install samba

Client: sudo apt-get install smbfs

Server Configuration

For Ubuntu 8.04 and later, we can browse to the location of the folder we would like to share, right-click the folder, and choose Sharing Options.

Configuration file: /etc/samba/smb.conf

Uncomment the security line, and add another line to make it look like this:

security = user

username map = /etc/samba/smbusers

This will set Samba to use the smbusers file for looking up the user list.

Create a Samba User

First run the smbpasswd utility to create a samba password for the user.

sudo smbpasswd -a <username>

Next add that username to the smbusers file.

sudo gedit /etc/samba/smbusers

and add the user name map, The format is <ubuntuusername> = "<samba username>".

Configure /etc/samba/smb.conf to share Ubuntu directories


path = /Music

comment = Music

available = yes

browseable = yes

public = yes

writable = yes

Then we are able to map a drive on windows using the following share format:

\\ubuntumachine\username(this is samba username)

Samba utilities and daemons

net smbd The Samba program, run as a daemon by default. Provides file and print services for Samba clients.

Smbclient Displays shares on a Samba server such as a Windows machine

smbd The Samba program, run as a daemon by default. Provides file and print services for Samba clients.

Smbpasswd Changes Windows NT password hashes on Samba and Windows NT servers

smbstatus Displays information about current smbd connections.

swat Samba Web Administration Tool. A browser-based editor for the smb.conf file

testparm Checks syntax of the smb.conf file.

/etc/init.d/samba restart | stop | start

Configuring a Samba Server Using shares-admin


When you install Samba, it copies all Linux users to the list of Samba users. If you add a user after you install Samba, you need to use the –a option to instruct smbpasswd to add the user to the list of Samba users.

sudo smbpasswd sam

sudo smbpasswd -a max

If a user has different usernames on the Linux and Windows systems, you must map the Windows username to a Linux username, Make sure all Linux users who will log in using Samba have Samba passwords.

swat: Configures a Samba Server

The swat (Samba Web Administration Tool, swat package) utility is a browser-based graphical editor for the smb.conf file. pen a browser and enter either or http://localhost:901 in the location bar.

Accessing Linux Shares from Windows

Browsing Shares

enter \\ubuntumachine\username in location bar.

Mapping a Share

From the menu at the top select "Tools" -> "Map Network Drive".

Accessing Windows Shares from Linux

smbtree: Displays Windows Shares

The smbtree utility displays a hierarchical diagram of available shares.

smbclient: Connects to Windows Shares

The smbclient utility functions similarly to ftp (page 729) and connects to a Windows share.

smbclient //JAM/D

smb: \> ls(help)

List public SMB shares: smbclient -L //server -U user

Connect to a SMB share: smbclient //server/share -U user

or: smbclient //server/share -U user%password

Browsing Windows Networks

From Nautilus, enter smb:/// in the location bar to browse the Windows shares on the network.

Mounting Windows Shares

The mount utility with a –t cifs option mounts a Windows share as if it were a Linux directory hierarchy. When you mount a Windows share, you can write to the files on the share; you cannot write to files on a share using smbclient.

sudo mount -t cifs //jam/d /share -o username=sam

You can omit the username argument and provide a blank password to mount shares that are visible to the guest user. Use the uid, file_mode, and dir_mode mount options with type cifs filesystems to establish ownership and permissions of mounted files.

$ sudo mount -t cifs //jam/d /share -o username=sam,uid=sam,file_mode=0644,dir_mode=0755


HOWTO: NFS Server/Client

Install NFS Server

sudo apt-get install nfs-kernel-server nfs-common portmap

Install NFS client

sudo apt-get install portmap nfs-common

Configuring NFS Server

Using shares-admin

The shares-admin utility stores this information in /etc/exports.

Restart nfs-server

/etc/init.d/nfs-kernel-server restart

Sharing directory with /etc/exports

The /etc/exports file is the access control list for exported directory hierarchies that NFS clients can mount; it serves as the access control list for file systems which may be exported to NFS clients.

The exports file controls the following NFS characteristics:

Which clients can access the server (see also "Security" on page 802)

Which directory hierarchies on the server each client can access

How each client can access each directory hierarchy

How client usernames are mapped to server usernames

Various NFS parameters

Each line in the exports file has the following format:

export-point client1(option-list) [client2(option-list) ... ]

General Options

ro (rw) (readonly) Permits only read requests on an NFS directory hierarchy. Use rw to permit read and write requests.

sync (async) (synchronize) Specifies that the server should reply to requests only after disk

changes made by the request are written to disk. The async option specifies that the server does not have to wait for information to be written to disk and can improve performance, albeit at the cost of possible data corruption if the server crashes or the connection is interrupted.

Wdelay (no_wdelay) (write delay) Causes the server to delay committing write requests when it anticipates that another, related request will follow, thereby improving performance by

committing multiple write requests within a single operation. The no_wdelay option does not delay committing write requests and can improve performance when the server receives multiple, small, unrelated requests.



/sales tom(ro,sync) jerry(ro,sync)


usage: exportfs [-aruv] [host:/path]

Give the command exportfs without any options to display a list of exported directory hierarchies and the systems each is exported to:

$ exportfs

exportfs -r

Where the System Keeps NFS Mount Information

cat /etc/exports

$ exportfs

cat /var/lib/nfs/etab

/var/lib/nfs/rmtab (remote mount table) On the server, lists the directory hierarchies that are mounted by client systems:

cat /var/lib/nfs/rmtab


On the client, this pseudofile displays the kernel mount table, which lists filesystems

mounted by the local system.

grep nfs\ /proc/mounts

showmount: Displays NFS Status Information

Without any options, the showmount utility displays a list of systems that are allowed to mount local directories. You typically use showmount to display a list of directory hierarchies that a server is exporting. To display information for a remote system, give the name of the remote system as an argument.

showmount -a

Testing the Server Setup

From the server, run the nfs-kernel-server init script with an argument of status. /etc/init.d/nfs-kernel-server status.

Also check that mountd is running:

$ ps -e | grep mountd

Next, from the server, use rpcinfo to make sure NFS is registered with portmap:

rpcinfo -p localhost | grep nfs

Repeat the preceding command from the client, replacing localhost with the name of the server. The results should be the same.

Access shared directories from Linux client computer

First, create a mountpoint on client computer:

mkdir /mnt/data

Mount the server:

mount nfs-server:/data /mnt/data

To see mounted file system and available disk space: df -h

Mounting at boot using /etc/fstab /files nfs rsize=8192,wsize=8192,timeo=14,intr /mnt/essniuser nfs rsize=8192,wsize=8192,timeo=14,intr


A Practical Guide to Ubuntu Linux

Ubuntu Linux Bible

Post a Comment


Java (159) Lucene-Solr (112) Interview (61) All (58) J2SE (53) Algorithm (45) Soft Skills (39) Eclipse (33) Code Example (31) Linux (24) JavaScript (23) Spring (22) Windows (22) Web Development (20) Tools (19) Nutch2 (18) Bugs (17) Debug (16) Defects (14) Text Mining (14) J2EE (13) Network (13) Troubleshooting (13) PowerShell (11) Problem Solving (10) Chrome (9) Design (9) How to (9) Learning code (9) Performance (9) UIMA (9) html (9) Http Client (8) Maven (8) Security (8) bat (8) blogger (8) Big Data (7) Continuous Integration (7) Google (7) Guava (7) JSON (7) Shell (7) ANT (6) Coding Skills (6) Database (6) Lesson Learned (6) Programmer Skills (6) Scala (6) Tips (6) css (6) Algorithm Series (5) Cache (5) Dynamic Languages (5) IDE (5) System Design (5) adsense (5) xml (5) AIX (4) Code Quality (4) GAE (4) Git (4) Good Programming Practices (4) Jackson (4) Memory Usage (4) Miscs (4) OpenNLP (4) Project Managment (4) Spark (4) Testing (4) ads (4) regular-expression (4) Android (3) Apache Spark (3) Become a Better You (3) Concurrency (3) Eclipse RCP (3) English (3) Happy Hacking (3) IBM (3) J2SE Knowledge Series (3) JAX-RS (3) Jetty (3) Life (3) Restful Web Service (3) Script (3) regex (3) seo (3) .Net (2) Android Studio (2) Apache (2) Apache Procrun (2) Architecture (2) Batch (2) Bit Operation (2) Build (2) Building Scalable Web Sites (2) C# (2) C/C++ (2) CSV (2) Career (2) Cassandra (2) Distributed (2) Fiddler (2) Firefox (2) Google Drive (2) Gson (2) How to Interview (2) Html Parser (2) Http (2) Image Tools (2) JQuery (2) Jersey (2) LDAP (2) Logging (2) Python (2) Software Issues (2) Storage (2) Text Search (2) xml parser (2) AOP (1) Application Design (1) AspectJ (1) Chrome DevTools (1) Cloud (1) Codility (1) Data Mining (1) Data Structure (1) ExceptionUtils (1) Exif (1) Feature Request (1) FindBugs (1) Greasemonkey (1) HTML5 (1) Httpd (1) I18N (1) IBM Java Thread Dump Analyzer (1) Invest (1) JDK Source Code (1) JDK8 (1) JMX (1) Lazy Developer (1) Mac (1) Machine Learning (1) Mobile (1) My Plan for 2010 (1) Netbeans (1) Notes (1) Operating System (1) Perl (1) Problems (1) Product Architecture (1) Programming Life (1) Quality (1) Redhat (1) Redis (1) Review (1) RxJava (1) Solutions logs (1) Team Management (1) Thread Dump Analyzer (1) Visualization (1) boilerpipe (1) htm (1) ongoing (1) procrun (1) rss (1)

Popular Posts