Showing posts with label Linux CLI. Show all posts
Showing posts with label Linux CLI. Show all posts

Wednesday, April 27, 2011

Linux - apt-get

The apt-get program is a command-line package manager, which should be used if the Add/Remove tool and Synaptic ever run into problems. It provides an advanced interface to APT, the underlying package management system which Ubuntu uses, but is reasonably easy to operate. Power users may find that apt-get is quicker to use and more powerful than the graphical options.

Text based methods can be used across Ubuntu, Kubuntu and Xubuntu, but require familiarity with the terminal. When helping users to install packages, you should consider using an AptURL instead of apt-get or aptitude.


Installing downloaded packages


You may wish to install a package you have downloaded from a website, rather than from a software repository. These packages are called .deb files. Because they may have been created for a different Linux distribution, you might find that there's dependency issues with Ubuntu, meaning that they may be uninstallable.

Package management via apt-get runs hand-in-hand with the /etc/apt/sources.list file.
To find a package which you have previously downloaded using Synaptic, aptitude or apt-get, look in /var/cache/apt/archives




Introduction to APT


"In the beginning there was the .tar.gz. Users had to compile each program that they wanted to use on their GNU/Linux systems. When Debian was created, it was deemed necessary that the system include a method of managing the packages installed on the machine. The name dpkg was given to this system. Thus the famous 'package' first came into being on GNU/Linux, a while before Red Hat decided to create their own 'rpm' system.

A new dilemma quickly took hold of the minds of the makers of GNU/Linux. They needed a rapid, practical, and efficient way to install packages that would manage dependencies automatically and take care of their configuration files while upgrading. Here again, Debian led the way and gave birth to APT, the Advanced Packaging Tool, which has since been ported by Conectiva for use with rpm and has been adopted by some other distributions."

Commands
 
All of these commands must be run as root or with superuser privileges, see sudo for more information. Replace with the name of the package you are attempting to install.
 
 apt-get install

to download without install

apt-get install -d


This command installs a new package.

apt-get build-dep

This command searches the repositories and installs the build dependencies for . If the package is not in the repositories it will return an error.


 
Ref : https://help.ubuntu.com/community/AptGet/Howto

Linux - MySQL Configuration

Configuration


You can edit the /etc/mysql/my.cnf file to configure the basic settings -- log file, port number, etc. For example, to configure MySQL to listen for connections from network hosts, change the bind-address directive to the server's IP address:

bind-address = 192.168.0.5


After making a change to /etc/mysql/my.cnf the mysql daemon will need to be restarted:
 
sudo /etc/init.d/mysql restart
 
If you would like to change the MySQL root password, in a terminal enter:
 
sudo dpkg-reconfigure mysql-server-5.1
 
The mysql daemon will be stopped, and you will be prompted to enter a new password.
 
 
 
Ref: https://help.ubuntu.com/10.04/serverguide/C/mysql.html

Linux - MySQL Installation

MySQL is a fast, multi-threaded, multi-user, and robust SQL database server. It is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software.


Installation

To install MySQL, run the following command from a terminal prompt:

sudo apt-get install mysql-server
During the installation process you will be prompted to enter a password for the MySQL root user.


Once the installation is complete, the MySQL server should be started automatically. You can run the following command from a terminal prompt to check whether the MySQL server is running:

sudo netstat -tap | grep mysql

When you run this command, you should see the following line or something similar:

tcp 0 0 localhost:mysql *:* LISTEN 2556/mysqld

If the server is not running correctly, you can type the following command to start it:

sudo /etc/init.d/mysql restart

Wednesday, January 13, 2010

Linux CLI - Webserver Apache - Virtual host

Okay, I'd make one extra suggestion:

Use a named host in a seperate config file. Thay way you don't get burned next time apache is upgraded.

First off make sure that the last line in /etc/httpd/httpd.conf is:

Include /private/etc/httpd/users/*.conf

It should be there by default. Then create a file in /private/etc/httpd/users called "customconfig.conf" (really whatever you want to call it). Add the following to that file:

>NameVirtualHostServer< Name myservername <- choose a severname you want here DocumentRoot "/Users/newmedia/websites" >NameVirtualHost<

Now, you're almost done. If you only want these sites accessible from your computer, add the following to /etc/hosts:

127.0.0.1 myservername

If other people need to access it, you need myservername added to the DNS for the area.

Now, from a webbrowser if you go to http://myservname apache will automatically use /Users/newmedia/websites. You can also put any server customizations in there, and test them out without affecting your main server, and if the main httpd.conf gets blown away your customization is unaffected.


Source :
http://forums.macrumors.com

Linux CLI - Webserver Apache - /etc/httpd/httpd.conf

In the terminal.

backup your config
sudo cp /etc/httpd/httpd.conf /etc/httpd/httpd.conf.bak

then edit the file
sudo vi /etc/httpd/httpd.conf

and find the line
DocumentRoot "/Library/WebServer/Documents"

Change to what you want the new httpd root to be.
In your case
DocumentRoot "/Users/newmedia/websites/"

then edit the line
Directory "/Library/WebServer/Documents"
to
Directory "/Users/newmedia/websites"

Also I change this line purely outta good practice

ServerSignature On
to
ServerSignature Off

After editing the httpd.conf you should verify it for any errors in the Terminal by typing:

sudo apachectl configtest

Enter your password and let it run. If it finds any errors it will say so. Otherwise it will say: Syntax OK

To restart apache (the web server) without going to System Preferences you can type in the Terminal:

sudo apachectl graceful

Sunday, January 10, 2010

Troubleshooting Skill - ssh: connect to host 10.0.0.1 port 22: Connection timed out lost connection

Could be:
a) You're not running sshd on Box A.
b) You're running a firewall somewhere that is blocking inbound port 22 to Box A.

On Box A run:
lsof -i :22

You should see (among other things) a line like the following showing it is LISTENing for connections. If not you may need to start your sshd or at least verify /etc/xinetd.d has it started.
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
sshd 1781 root 3u IPv6 4892 TCP *:ssh (LISTEN)

If above is running you can try "telnet 22" to see if this times out as well. If so it would indicate something isn't allowing connections even though you're LISTENing for them.

Possible culprits:
iptables (or some other firewall software) on Box A. If iptables you can run "service iptables stop" then test it. If it works you know it was iptables. You'd then need to figure out a rule to allow port 22 from Box B OR leave iptables off. (You should make a rule. Command to restart iptables is "service iptables start". Turn it off just to see if it is the problem.)

SELinux on Box A. SELinux is a new NSA sponsored security sort of like a firewall on steroids and it is a huge pain for most people. Most people just disable it.

A physical switch/firewall between Box A and Box B that prevents port 22 traffic to Box A. For this you'd have to get a Network person involved if you're not the one who administers these. Typically between floors in buildings there are "VLANS" that do this kind of blocking.


I haven't used Firestarter but I gather from other comments I've seen that it is just a GUI front end for iptables. Since you can configure iptables from command line the answer would be yes.

"iptables -L" will list your current rules from command line.

In UNIX/Linux almost everything can be done from the command line even if it is sometimes easier to do from GUI. (Some GUI utilities even have logging modes that will show you the command line they're running behind the scenes.) This is mainly to allow for scripting tasks. I've been doing UNIX for so long it often doesn't even occur to me to look for a GUI solution even on the systems where I have KDE or Gnome running.

Referring from:
http://www.linuxquestions.org/questions/linux-server-73/ssh-connection-to-host-port-22-connection-timed-out-lost-connection-537110/

Tuesday, November 17, 2009

Linux CLI - How to broadcast a message to all users - using wall

1. As the main input of wall is a file, we will first create our message file.Type :

$ echo 'Please note that in two more hours, and for one hour, you will not be able to use the SQL database, please save all your job before, and quit any application using it'> message.txt

2. OK, now we have our message ready, it is time to send it to the users

$ wall < message.txt

 Try yourself!!!

Sunday, October 25, 2009

Linux CLI - Remove/Delete



1. To remove files
rm


2. To remove empty directory
rmdir 


3. To remove a directory along with all of its contents, type:
rm -fr

*use this with caution as there is no undelete.


4. To uninstall packages
apt-get remove  

Linux CLI - How to clear history

For fast clearing just type 'history -c' command that will clears the terminal history.

Another alternative by googling..

 1. Just put this command in your .bashrc file

a. If you don't even want to keep on in the first place
export HISTSIZE=0

b. Prevent less from creating a history file.
export LESSHISTFILE="-"

c.Prevent a bash history file from ever being saved.
unset HISTFILE


2. Your history will be available in ram for each bash session, but will be gone once you log out

rm -fr ~/.bash_history

ln -s /dev/null ~/.bash_history


3. You could add the following line to the end of your .bash_logout file:

rm -f .bash_history


Test it!!!

Linux CLI - Check size of Directory and sub-directories

1. Display free disk space

df --


2. Display disk usage statistics

du --


Example:


1. Check disk total free space
df -h


2. Check size of directory by list down all the contents
du -ah /path/to/dir



3. Only display total directory size
du -sh /path/to/dir



p/s - normally I only use du -sh & df -h