How To: Customizing Fortunes

Ever wanted the bubble above the “fortune-teller” animal to display something that you have created(with YOUR Name of course)? It’s pretty simple to display your “words of wisdom” as fortunes each time you open the terminal or perform a console login.
1)First of all, create a file containing the fortunes that you want to display. Begin the contents of the file with a % sign. Then fill it with the phrases, expressions or sayings of your choice. Remember to separate each phrase using the % sign.
2)Generate a “.dat” file for the file that was created in step 1. This can be done by using the “strfile” command as shown below

strfile -r filename

Now a “.dat” file with the same name as the file created in step 1 will be generated.
3)Go to the directory “/usr/share/games/fortunes” (with administrator privileges!). This directory may vary and can be found out from fortune man page.
4)Simply copy and paste the files created in steps 1 and 2 into the directory in step 3.
5)Prevent sayings by Shakespeare or other people(no Offense!) from popping up by deleting their corresponding “.dat” files.(I strongly advice you to make a backup of these “.dat” files before getting rid of them!)

Close the directory and you are good to go! Show it off to your “Windows obsessed” friends. Let them know about the Flexibility that Linux offers!

ONLY for those who like to get to the bottom of things:
strfile command as described in its man-page “reads a file containing groups of lines separated by a line containing a single percent `%’ sign (or other specified delimiter character) and creates a data file which contains a header structure and a table of file offsets for each group of lines.” This header and offset table are used by the fortune program to display the fortunes contained in a particular file. When a particular entry in the offset table is added to the header value, it points to the corresponding fortune which then gets displayed. The “-r” option causes the entries in the offset table to be arranged randomly. This is because, even if the offset table entries were read in a sequential manner we will still get randomized fortunes.
unstr command takes the “.dat” data file as input and prints the contents of the original file (the one containing fortunes separated by ‘%’ character) in the order in which the offset table entries were made.

wp zend framework plugin

Here you can find more info about wp-zend-framework wordpress plugin. The only thing you have to do is to upload the plugin, install and activate it. Then, you will be able to use all the features offered by Zend Framework to your wordpress site.

 

You can download the plugin from wp-zend-framework

Installing CUDA on Ubuntu 12.04

If you’re looking for a quick and easy way to get started with GPGPU computing, you really can’t go wrong with nVidia’s CUDA. It is a parallel computing architecture that harnesses the power of GPUs in order to achieve significant speedups in problems that would have otherwise taken a significantlylonger time while executing on the CPU. It is the most mature architecture for GPGPU computing, with a wide number of libraries based around it. This guide is going to cover the installation of the CUDA toolkit and SDK on Ubuntu, along with the necessary development drivers.

NOTE – For CUDA to work, you must have an nVidia GPU which is CUDA capable. If you have an ATI GPU, this guide is not for you. You can, however, look into OpenCL.

If your GPU meets the requirements, head over to the CUDA Downloads page and download the toolkit, drivers and SDK from under the Linux section, taking care to choose the 32 or 64-bit version depending on your system. If you’re not sure, run
uname -m
in a terminal. i686 denotes a 32-bit system, and x86_64 denotes a 64-bit one. For the toolkit, I chose the one titled Ubuntu 11.04, although either of the Ubuntu toolkits should work just fine.

Save all three files in an easy to access location, like your Home folder. Do not proceed with this guide until you’ve either memorized the following steps or printed them for easy reference!

STEP I – Driver installation

Make sure the requisite tools are installed using the following command –

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

Next, blacklist the required modules (so that they don’t interfere with the driver installation) –

gksu gedit /etc/modprobe.d/blacklist.conf

Add the following lines to the end of the file, one per line –

blacklist amd76x_edac
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv

Save the file and exit gedit.

I would like add a comment right now, in my Ubuntu installation the entry “blacklist amd76x_edac” allready existed. So check if any of the above entries allready exists at your blacklist.conf file.

In order to get rid of any nVidia residuals, run the following command in a terminal –

sudo apt-get remove --purge nvidia*

This may take a while, so be patient. Once it’s done, reboot your machine. At the login screen, don’t login just yet. Press Ctrl+Alt+F1 to switch to a text-based login. Login and switch to the directory which contains the downloaded drivers, toolkit and SDK. Run the following commands –

sudo service lightdm stop
chmod +x devdriver*.run

where devdriver*.run is the full name of your driver. Next, start the installation with –

sudo ./devdriver*.run

Follow the onscreen instructions. If the installer throws up an error about nouveau still running, allow it to create a blacklist for nouveau, quit the installation and reboot. In that case, run the following commands again –

sudo service lightdm stop
sudo ./devdriver*.run

The installation should now proceed smoothly. When it asks you if you want the 32-bit libraries and if you want it to edit xorg.conf to use these drivers by default, allow both.

Reboot once the installation completes.

STEP II – CUDA toolkit installation

Next, enter the following in a terminal window (in the directory where the files are stored) –

chmod +x cudatoolkit*.run
sudo ./cudatoolkit*.run

where cudatoolkit*.run is the full name of the toolkit installer. I recommend leaving the installation path to its default setting (/usr/local/cuda) unless you have a specific reason for not doing so.

STEP III – CUDA SDK installation

Once the toolkit is installed, enter the following in a terminal –

chmod +x gpucomputingsdk*.run
sudo ./gpucomputingsdk*.run

where gpucomputingsdk*.run is the full name of the SDK installer. Again, follow the instructions onscreen to complete the installation.

You’re now ready to journey into the world of CUDA and GPGPU computing. If you’re looking for books on the same, check out this page.

How to test postfix through telnet

Telnet basics

Telnet is the most basic mail client. It does the same thing as the bigger clients you use on your workstation (such as Thunderbird, Outlook, Mail, etc) – it sends mail.

However, instead of being wrapped in a nice GUI it is a command line tool that can be used to diagnose our postfix installation (and to send mail!).

This is a primer for telnet. I won’t be going into great detail of the why’s and the how’s of every aspect of telnet and the responses we (should) receive.

Setting up mail servers can be a complicated issue and there are some incredible large and detailed tomes and manuals available for those who need to get into the minute detail.

However, following the articles will allow you to understand the basics and know what to look for should you want more detail.

Email details

When you send an email you can use the analogy of physically posting a letter:

You greet the postman. You hand over the envelope which should have the address (recipient) and the sender’s address – inside the envelope will be the actual letter, or the data.

Going with that analogy, we need a way of authenticating or confirming all those details.

Greeting

We’ll start of the sequence by connecting to the mail server and greeting the postman.

On the Slice enter:

telnet mail.demoslice.com 25

This starts the telnet session on port 25.

You should receive a 220 response:

Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 220 mail.demoslice.com ESMTP Postfix (Ubuntu)

Good.

Next we can greet the postman:

HELO test.demoslice.com

Note the test subdomain doesn’t exist – it is simply a way of greeting the mail server.

The mail server should respond with a confirmation of who it is:

250 mail.demoslice.com

Envelope

Now we have greeted the postman and got the correct responses we can start to fill out the envelope for our letter.

We start by letting the server know who the sender is:

MAIL FROM:<paul@demoslice.com>

If the mail server accepts the sender address, you will get another ‘250’ output:

250 2.1.0 Ok

Good.

Now we can sort out to whom we are sending the letter:

RCPT TO:<demo@demoslice.com>

We are hoping for a 250 response:

250 2.1.5 Ok

Again, good news.

You can add more recipients – unlike a physical letter, the same email can be sent to multiple recipients.

Data

Now we come to the ‘meat’ of the letter: the data.

To start the main body of the message:

DATA

The response is fairly sparse:

354 End data with <CR><LF>.<CR><LF>

Now you need to enter the subject and the body.

Note you need to physically type the word ‘Subject:’

Subject: test message

Press enter/return and then you can type the body of the message:

This is the body of the message!

As when we used the ‘mail’ command in a previous article, we need to enter a single period (.) to indicate we have finished the body of the message.

As before, we are rather hoping for a 250 response:

. 250 2.0.0 Ok: queued as 9620FF0087

Nice.

Quit

Well, we’re done with telnet for the moment so we can quit:

QUIT

This will dump you back at the bash prompt:

221 2.0.0 Bye Connection closed by foreign host. You have new mail in /var/mail/demo

Ooh!

I have new mail in /var/mail/demo

You have mail

Let’s use the ‘tail’ command to read the end of the mail file:

tail -n 15 /var/mail/demo

That particular command parses the last 15 lines of the /var/mail/demo file (which is where our mail is kept).

If you don’t see all of the mail as shown below, you can adjust the number of lines to, say, 20.

In my case, the output was as follows:

From paul@demoslice.com Wed Aug 6 10:33:20 2008 Return-Path: <paul@demoslice.com> X-Original-To: demo@demoslice.com Delivered-To: demo@demoslice.com Received: from test.demoslice.com (localhost [127.0.0.1]) by mail.demoslice.com (Postfix) with SMTP id 9620FF0087 for <demo@demoslice.com>; Wed, 6 Aug 2008 10:28:43 +0000 (UTC) Subject: test message Message-Id: <20080806103059.9620FF0087@mail.demoslice.com> Date: Wed, 6 Aug 2008 10:28:43 +0000 (UTC) From: paul@demoslice.com To: undisclosed-recipients:; This is the body of the message!

Well that’s pretty cool.

Details

It goes without saying (even though I am going to say it) that there is far, far more to it than the basics shown above.

It is simply impossible to go into all the details of what is possible with email headers and messages, encodings and the details of telnet.

However, this introduction should show how mail works and what steps are taken when mail is sent and received.

Perhaps you can begin to see why some legitimate mail may be seen as spam email – if any of the steps above failed or gave the wrong response then warning flags are raised.

A wrong hostname will mean mail sent from the Slice does not identify itself properly. Improperly formatted addresses or message bodies can raise eyebrows and flags.

Summary

Telnet is a very simple mail client and can be used to diagnose our postfix install.

Controlled via the command line we can see if the responses from our installation are correct.

Once done, we were then able to read our mail.

Although that is well and good, it would be a bit of a annoyance having to read our mail from the command line. As such, we will look at pop and imap access in later articles.

Root Sudo

Before, going on reading about sudo keep in mind, that for help with configuring sudo privileges via its configuration file /etc/sudoers, please see Sudoers.

Background Information

In Linux (and Unix in general), there is a SuperUser named Root. The Windows equivalent of Root is Administrators group. The SuperUser can do anything and everything, and thus doing daily work as the SuperUser can be dangerous. You could type a command incorrectly and destroy the system. Ideally, you run as a user that has only the privileges needed for the task at hand. In some cases, this is necessarily Root, but most of the time it is a regular user.

By default, the Root account password is locked in Ubuntu. This means that you cannot login as Root directly or use the su command to become the Root user. However, since the Root account physically exists it is still possible to run programs with root-level privileges. This is where sudo comes in – it allows authorized users (normally “Administrative” users; for further information please refer to AddUsersHowto) to run certain programs as Root without having to know the root password.

This means that in the terminal you should use sudo for commands that require root privileges; simply prepend sudo to all the commands you would normally run as Root. For more extensive usage examples, please see below. Similarly, when you run GUI programs that require root privileges (e.g. the network configuration applet), use graphical sudo and you will also be prompted for a password (more below). Just remember, when sudo asks for a password, it needs YOUR USER password, and not the Root account password.

Please keep in mind, a substantial number of Ubuntu users are new to Linux. There is a learning curve associated with any OS and many new users try to take shortcuts by enabling the root account, logging in as root, and changing ownership of system files.

Example: Broken system via (ab)use of root by a new user

Please note: At the time of the post, this was the users first post on the Ubuntu forums. While some may say this is a “learning experience”, learning by breaking your system is frustrating and can result in data loss.

When giving advice on the Ubuntu Forms and IRC, please take the time to teach “the basics” such as ownership, permissions, and how to use sudo / gksu / kdesudo in such a way that new users do not break systems.

 

Advantages and Disadvantages

 

Benefits of using sudo

Some benefits of leaving Root logins disabled by default include the following:

  • The Ubuntu installer has fewer questions to ask.
  • Users don’t have to remember an extra password (i.e. the root password), which they are likely to forget (or write down so anyone can crack into their account easily).
  • It avoids the “I can do anything” interactive login by default (e.g. the tendency by users to login as an “Administrator” user in Microsoft Windows systems), you will be prompted for a password before major changes can happen, which should make you think about the consequences of what you are doing.
  • sudo adds a log entry of the command(s) run (in /var/log/auth.log). If you mess up, you can always go back and see what commands were run. It is also nice for auditing.
  • Every cracker trying to brute-force their way into your box will know it has an account named Root and will try that first. What they don’t know is what the usernames of your other users are. Since the Root account password is locked, this attack becomes essentially meaningless, since there is no password to crack or guess in the first place.
  • Allows easy transfer for admin rights, in a short term or long term period, by adding and removing users from groups, while not compromising the Root account.
  • sudo can be setup with a much more fine-grained security policy.
  • The Root account password does not need to be shared with everybody who needs to perform some type of administrative task(s) on the system (see the previous bullet).
  • The authentication automatically expires after a short time (which can be set to as little as desired or 0); so if you walk away from the terminal after running commands as Root using sudo, you will not be leaving a Root terminal open indefinitely.

 

Downsides of using sudo

Although for desktops the benefits of using sudo are great, there are possible issues which need to be noted:

  • Redirecting the output of commands run with sudo requires a different approach. For instance consider sudo ls > /root/somefile will not work since it is the shell that tries to write to that file. You can use ls | sudo tee -a /root/somefile to append, or ls | sudo tee /root/somefile to overwrite contents. You could also pass the whole command to a shell process run under sudo to have the file written to with root permissions, such as sudo sh -c "ls > /root/somefile".
  • In a lot of office environments the ONLY local user on a system is Root. All other users are imported using NSS techniques such as nss-ldap. To setup a workstation, or fix it, in the case of a network failure where nss-ldap is broken, Root is required. This tends to leave the system unusable unless cracked. An extra local user, or an enabled Root password is needed here. The local user account should have its $HOME on a local disk, _not_ on NFS (or any other networked filesystem), and a .profile/.bashrc that doesn’t reference any files on NFS mounts. This is usually the case for Root, but if adding a non-Root rescue account, you will have to take these precautions manually.
    • Alternatively, a sysadmin type account can be implemented as a local user on all systems, and granted proper sudo privileges. As explained in the benefits section above, commands can be easily tracked and audited.

 

 

 

 

 

Usage

  • When using sudo, your password is stored by default for 15 minutes. After that time, you will need to enter your password again.
  • Your password will not be shown on the screen as you type it, not even as a row of stars (******). It is being entered with each keystroke!

 

sudo

To use sudo on the command line, preface the command with sudo, as below: Example #1

sudo chown bob:bob /home/bob/*

Example #2

sudo /etc/init.d/networking restart

To repeat the last command entered, except with sudo prepended to it, run:

sudo !!

 

 

Graphical sudo

You should never use normal sudo to start graphical applications as Root. You should use gksudo (kdesudo on Kubuntu) to run such programs. gksudo sets HOME=~root, and copies .Xauthority to a tmp directory. This prevents files in your home directory becoming owned by Root. (AFAICT, this is all that’s special about the environment of the started process with gksudo vs. sudo).

Examples:

gksudo gedit /etc/fstab

or

kdesudo kate /etc/X11/xorg.conf
  • To run the graphical configuration utilities, simply launch the application via the Administration menu.
  • gksudo and kdesudo simply link to the commands gksu and kdesu

 

Drag & Drop sudo

This is a trick from this thread on the Ubuntu Forums.

Create a launcher with the following command:

gksudo "gnome-open %u"

When you drag and drop any file on this launcher (it’s useful to put it on the desktop or on a panel), it will be opened as Root with its own associated application. This is helpful especially when you’re editing config files owned by Root, since they will be opened as read only by default with gedit, etc.

 

Users

 

Allowing other users to run sudo

To add a new user to sudo, open the Users and Groups tool from System->Administration menu. Then click on the user and then on properties. Choose the User Privileges tab. In the tab, find Administer the system and check that.

  • In Hardy Heron and newer, you must first Unlock, then you can select a user from the list and hit Properties. Choose the User Privileges tab and check Administer the system.

 

/!\" src= In the terminal this would be: sudo adduser <username> admin, where you replace <username> with the name of the user (without the <>).

 

Logging in as another user

Please don’t use this to become Root, see further down in the page for more information about that.

sudo -i -u <username>

For example to become the user amanda for tape management purposes.

sudo -i -u amanda

The password being asked for is your own, not amanda’s.

 

root account

 

Enabling the root account

IconsPage/IconWarning3.png Enabling the Root account is rarely necessary. Almost everything you need to do as administrator of an Ubuntu system can be done via sudo or gksudo. If you really need a persistent Root login, the best alternative is to simulate a Root login shell using the following command… IconsPage/IconWarning3.png

 

sudo -i

 

To enable the Root account (i.e. set a password) use:

sudo passwd root

Use at your own risk!

 

IconsPage/dont.png Logging in to X as root may cause very serious trouble. If you believe you need a root account to perform a certain action, please consult the official support channels first, to make sure there is not a better alternative. IconsPage/dont.png

 

 

 

Re-disabling your root account

 

 

IconsPage/info.png If for some reason you have enabled your root account and wish to disable it again, use the following command in terminal… IconsPage/info.png

 

sudo passwd -dl root

 

 

 

 

Other Information

 

Misconceptions

  • Isn’t sudo less secure than su?
    • The basic security model is the same, and therefore these two systems share their primary weaknesses. Any user who uses su or sudo must be considered to be a privileged user. If that user’s account is compromised by an attacker, the attacker can also gain root privileges the next time the user does so. The user account is the weak link in this chain, and so must be protected with the same care as Root.

      On a more esoteric level, sudo provides some features which encourage different work habits, which can positively impact the security of the system. sudo is commonly used to execute only a single command, while su is generally used to open a shell and execute multiple commands. The sudo approach reduces the likelihood of a root shell being left open indefinitely, and encourages the user to minimize their use of root privileges.

  • I won’t be able to enter single-user mode!
    • The sulogin program in Ubuntu is patched to handle the default case of a locked root password.
  • I can get a root shell from the console without entering a password!
    • You have to enter your password.Console users have access to the boot loader, and can gain administrative privileges in various ways during the boot process. For example, by specifying an alternate init(8) program. Linux systems are not typically configured to be secure at the console, and additional steps (for example, setting a root password, a boot loader password and a BIOS password) are necessary in order to make them so. Note that console users usually have physical access to the machine and so can manipulate it in other ways as well.

 

Special notes on sudo and shells

None of the methods below are suggested or supported by the designers of Ubuntu.

Please do not suggest this to others unless you personally are available 24/7 to support the user if they have issues as a result of running a shell as Root.

 

To start a root shell (i.e. a command window where you can run Root commands), starting Root’s environment and login scripts, use:

sudo -i     (similar to sudo su - , gives you roots environment configuration)

To start a root shell, but keep the current shell’s environment, use:

sudo -s     (similar to sudo su)

For a brief overview of some of the differences between su, su -, and sudo -{i,s} see : Ubuntu Forums Post with nice table .

For a detailed description of the differences see man su and man sudo .

 

Remove Password Prompt For sudo

IconsPage/IconDialog-Warning1.png If you disable the sudo password for your account, you will seriously compromise the security of your computer. Anyone sitting at your unattended, logged in account will have complete Root access, and remote exploits become much easier for malicious crackers. IconsPage/IconDialog-Warning1.png
  • This method is NOT suggested nor supported by the designers of Ubuntu.
  • Please do not suggest this to others unless you personally are available 24/7 to support the user if they have issues as a result of running a shell as Root.

These instructions are to remove the prompt for a password when using the sudo command. The sudo command will still need to be used for Root access though.

Edit the sudoers file

Open a Terminal window. Type in sudo visudo. Add the following line to the END of the file (if not at the end it can be nullified by later entries):

<username> ALL=NOPASSWD: ALL

Replace <username> with your user name (without the <>). This is assuming that Ubuntu has created a group with the same name as your user name, which is typical. You can alternately use the group users or any other such group you are in. Just make sure you are in that group. This can be checked by going to System->Administration->Users and Groups

Example:

michael ALL=NOPASSWD: ALL

Type in ^x to exit. This should prompt for an option to save the file, type in Y to save.

Log out, log back in. This should now allow you to run the sudo command without being prompted for a password.

 

Reset sudo timeout

You can make sure sudo asks for password next time by running:

sudo -k

The default sudo timeout length can be changed by following this article: RootSudoTimeout.

 

How to Enable Root User in Ubuntu

This article, it’s going to be a first thing to do (in my opinion), after installing Ubuntu. By default in Ubuntu the Super User Root is disabled for security reasons. Thus, when you want to act like a SuperUser you have to call sudo actions instead of using a su at an administering session in Terminal. There are times that this security is useful, but there are times that this procedure is annoying. The point of view is very important to decide whether this has advantages or disadvantages. Read this article to see some of them.

 

By default, root account password is locked in Ubuntu. So, when you do su –, you’ll get Authentication failure error message as shown below.

$ su -
Password:
su: Authentication failure

Enable super user account password on Ubuntu

First, set a password for root user as shown below.

$ sudo passwd root
[sudo] password for giorgos:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Now with the new password you can login as super user with su command

$ su -
Password:
#

Disable super user account password on Ubuntu

Later if you don’t want to use su anymore, you can lock the root user password using one of the methods shown below

$ sudo passwd -l root

( or )

$ sudo usermod -p '!' root