Difference between revisions of "Ubuntu Server Setup"

From rbachwiki
Jump to navigation Jump to search
(Created page with "== Turn on Mod Rewrite == <pre> 1. a2enmod rewrite 2. restart apache server 3. edit vhost file AllowOverride all </pre> == Shell Scripting == <pre> • Scripts must be ch...")
 
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Upgrading Ubuntu Server to a new release ==
* Install update-manager-core if it is not already installed:
sudo apt-get install update-manager-core
* Launch the upgrade tool:
sudo do-release-upgrade
== Turn on Mod Rewrite ==
== Turn on Mod Rewrite ==
<pre>
<pre>
Line 6: Line 16:
</pre>
</pre>


== Shell Scripting ==
== Apache Commands==
 
*List apache packages and versions
  dpkg -l | grep apache
 
*shows version of ubnuntu
cat /etc/issue
 
*shows version of ubuntu
cat /etc/*-release
 
*give detail status of the service
apachectl status
 
*Gives info on where config file is located
**apachectl -V
*Search the entire server for the file
**find / | grep "apache2\.conf"
* Info for each line in the .conf File
** http://httpd.apache.org/docs/current/mod/directives.html
* Displays Config Info about all Virtual Hosts
** apachectl -t -D DUMP_VHOSTS
* Display All Modules form Apache
** apachectl -t -D DUMP_MODULES
*Enable and Disable Modules
*Directory for Modules
**/etc/apache2/modes-available and /etc/apache2/mods-enabled
**a2enmod and a2dismod will enable of disable modules
*Find where the apache error log is located
**grep -Ri ErrorLog /etc/apache2
*Watch Error log in realtime
**tail -f error.log
*Tools to Analize log files
**AWStats - awstats.sourceforge.net
*GoAccess - Terminal app
**goaccess.prosoftcorp.com
 
 
== Using SMTP to send email==


<pre>
<pre>
• Scripts must be chmod 755 so they can execute
apt-get install php-pear


• #!/bin/bash (add to the top of the shell script so it can use the bash shell to interpret the script, you can also add python or other shell programs)
pear install Mail


• Postional Parameters: $0 ... $9 $@ to access all 0-9 // like in a loop
pear install Net_SMTP


• Exit Status return Codes: Range from 0 to 255: 0 = success: Other than 0 = error condition: use man or info to find meanign of exit status
restart apache


&bull, $? contains the return code of the previously executed command
## you have to include this in your code.


ls /not/here
require_once 'Mail.php';
    echo "$?"
Another Code example


 
## there is a lot more info you have to provide. do a search or pear mail
    HOST="google.com"
      ping -c 1 $HOST # -c 1 means it will send 1 ping
      if["$?" -eg "0"]
      then
          echo "$HOST reachable"
      else
          "$HOST unreachable"
      fi
&& and ||
-the second statement only executes if the first one was successfull
mkdir /tmp/bak && cp test.txt /tmp/bak/
-the second statement will execute only if the first one fails
cp test.txt /tmp/bak/ || cp test.txt /tmp
• chain multiple commands together using a ; (semicolon) cp test.txt /tmp/ ; cp test.txt /bak


</pre>
</pre>
== Setting up Postfix to send mail ==


===File Operators (test)===
<pre>
<pre>
-d FILE -true if is a directory
sudo apt-get install postfix
-e FILE True if file exists
 
-f FILE True if file exist and is a regular file
Options
-r FILE True if file is readable by you
 
-s FILE True if file exists and is not empty
Satellite
-w FILE True if file is writable by you
domain.com
-x FILE True if file is executable by you
smtp server= ip address or smtp.domain.com
-z FILE True if string is empty
service restart postfix
-n FILE True if string is not empty
 
String1=String2 true if strings are equal
Postfix config file
String1 != string2 True if the strings are not equal
/etc/postfix/main.cf
arg1 -eq arg2 equal
arg1 -ne arg2 not equal
arg1 -lt arg2 less than
arg1 -le arg2 less than or equal to
arg1 -gt arg2 greater than
arg1 -ge arg2 greater than or equal to
read -p "Prompt to dispaly" VarableName accepting user input
</pre>
</pre>
=== for loop to rename all jpg files with the date ===
== Giving Root Privileges to another Account ==
 
<pre>
<pre>
  #!/bin/bash
edit  /etc/sudoers.tmp
  PICTURES=$(ls *.jpg)
 
  DATE=$ (date +%F)
#User previlege specification
 
root  ALL=(ALL:ALL)ALL
 
#  copy the settings of the root and adapt it to your username
 
alex ALL=(ALL:ALL)ALL


  for PICTURES IN $PICTURES
      do
          echo "Renaming ${PICTURE} to ${DATE} - ${PICTURE}"
          mv $[PICTUE} ${DATE}-${PICTURE}
  done


  // Output
  renaming bear.jpg to 2015-03-06-bear.jpg
</pre>
</pre>


=== Adding exit commands to scripts ===
== Installing Node.js ==


<pre>
<pre>
    #!/bin/bash
sudo apt-get install python-software-properties
      HOST="google.com"
 
      ping -c 1 $HOST
add-apt-repository ppa:chris-lea/node.js
      IF [ "$?" -ne"0" ]
 
      then
          echo "$HOST unrechale"
 
          exit 1
apt-get update
      fi
apt-get install nodejs npm
      exit 0
 
 
</pre>
</pre>


=== Creating a Function ===
== Search Repositories ==
 
<pre>
<pre>
function function-name() {# code goes here}
sudo apt-cache search python
Calling a Function
function hello() {
    echo "hello:
    }
    hello (you don't need the () just call the name of the function)
   
**Positional Parameters and passing info to a funciton


will search the cached repo of all python</pre>


    #!/bin/bash
== Changing Mac Address Linux ==
  function hello(){
      echo "hello $1"


  }
<pre>
ifconfig wlan0 down


  hello robert # robert is passed to the function hello
ifconfig wlan0 hw ether de:ad:be:ef:co:fe
  #output is hello Robert
**Outputting miltple calls to a function


ifconfig wlan0 up


    #!/bin/bahs
ifconfig wlan0 | grep HWaddr
      funciton hello() {
</pre>
      for NAME in $@
      do
          echo "Hello $NAME"
      done
  }


  hello robert bob dan
== Repair Perl Locale Errors on Ubuntu  ==


  Output
<pre>
  hello robert bob dan
sudo apt-get install language-pack-en-base
Using Wildcards
sudo dpkg-reconfigure locales
* -matches zero or more characters
if that dosent work then try this
*.txt
export LANGUAGE=en_US.UTF-8
a*
export LANG=en_US.UTF-8
a*.txt
export LC_ALL=en_US.UTF-8
? - matches exactly one character
locale-gen en_US.UTF-8
?.txt
apt-get install locales
a?
dpkg-reconfigure locales
a?.txt
[] character class - matches any of the characters included between the brackets. Matches exactly one character.
[aeiou]* exampld: ls -la [abge]*
ca[nt] matches:(it will match either the n or the t)
can, cat, candy, catch
[!] Matches any characters NOT included between the brackets. Matches exactly one character.
[!aeiou]* would match below bacause it does not start with any of those letters
baseball, cricket
Select a range
[a-g]* matches files that start with a,b,c,d,e,f,g
[3-6]* matches all files start with 3,4,5,6
Using predefined Character Classes
[[:alpha:]]
[[:alnum:]]
[[:digit:]]
[[:lower:]]
[[:upper:]]
[[:space:]]


#!/bin/bash
cd /var/www/bash
  # there's a space after the "if", space afer ! then a space after "[", space before "]"
if [ ! -d  /var/www/bash/text/ ]
then
    mkdir /var/www/bash/text
fi
for FILE in *.txt
do
    echo "Copying $FILE"
    cp $FILE /var/www/bash/text
done
Case Statements
</pre>
</pre>


== Apache Commands==
== Remove Old host keys from Known_hosts  ==


<pre>
<pre>
List apache packages and versions
ssh-keygen -f "/root/.ssh/known_hosts" -R 192.168.20.133
dpkg -l | grep apache
 
shows version of ubnuntu
</pre>
cat /etc/issue
shows version of ubuntu
cat /etc/*-release
give detail status of the service
apachectl status
Gives info on where config file is located
apachectl -V
Search the entire server for the file
find / | grep "apache2\.conf"
Info for each line in the .conf File
http://httpd.apache.org/docs/current/mod/directives.html
Displays Config Info about all Virtual Hosts
apachectl -t -D DUMP_VHOSTS
Display All Modules form Apache
apachectl -t -D DUMP_MODULES
Enable and Disable Modules
Directory for Modules
/etc/apache2/modes-available and /etc/apache2/mods-enabled
a2enmod and a2dismod will enable of disable modules
Find where the apache error log is located
grep -Ri ErrorLog /etc/apache2
Watch Error log in realtime
tail -f error.log
Tools to Analize log files
AWStats - awstats.sourceforge.net
GoAccess - Terminal app
goaccess.prosoftcorp.com
</pre>


== ==
== Sync Time with ntp server ==


<pre>
<pre>
Using the command line, you can use dpkg-reconfigure tzdata.


dpkg-reconfigure tzdata
Follow instructions
install ntp
sudo apt-get install ntp
</pre>
</pre>


==  ==
== scp without password - keygen ==


<pre>
<pre>
Generate a public/private key pair on the local machine.


    ssh-keygen -t rsa
In response, you should see:
Generating public/private rsa key pair
Enter file in which to save the key ...
Press Enter to accept this.
In response, you should see:
Enter passphrase (empty for no passphrase):
You don't need a passphrase, so press Enter twice.
In response, you should see:
Your identification has been saved in ...
Your public key has been saved in ...
Note the name and location of the public key just generated. It always ends in .pub.
Copy the public key id_rsa.pub just generated to all of your remote Linux boxes. You can use scp or FTP or whatever to make the copy. Assuming you're using root--again, see my warning in step 1--the key must be contained in the file /root/.ssh/authorized_keys. Or, if you are logging in as a user, for example, clyde, it would be in /home/clyde/authorized_keys. Notice that the authorized_keys file can contain keys from other PCs. So, if the file already exists and contains text, you need to append the contents of your public key file to what already is there
cat id_rsa.pub >> authorized_keys
The files are stored in root/.ssh
if the authorized_keys file does not exist create it and copy the id_rsa.pub from the other machine and paste in the authorized_keys file
do it for each machine so each machine has the other .pub info inthe authorized_key file
if the file already exist, just edit it and paste the other machine's .pub info.
</pre>
</pre>


== ==
== Virtual Host Setup to display domain without the www ==


<pre>
<pre>
Setup Virtual host so www.domain.com works and domain.com works.
ServerName www.domain.com


ServerAlias domain.com
This will allow the domain to come up with the www
</pre>
</pre>


==  ==
== Finding out Package Dependencies with apt-redepends ==


<pre>
<pre>
1 Installing apt-rdepends


apt-rdepends can be installed as follows:
apt-get install apt-rdepends
If you are on Ubuntu and are not logged in as root, use
sudo apt-get install apt-rdepends
apt-rdepends can be used as follows:
apt-rdepends <packagename>
For example, to find out all dependencies of the package wget, run:
apt-rdepends wget
For most packages, the output is even longer and might not fit on your screen. In these cases you can pipe the output into more (or less), e.g. as follows:
apt-rdepends apache2 | more
apt-rdepends apache2 | less</pre>
== Set Time zone in Ubuntu Server ==
<pre>
dpkg-reconfigure tzdata
</pre>
</pre>


== ==
== Installing Java in Ubuntu ==


<pre>
<pre>
sudo add-apt-repository ppa:sun-java-community-team/sun-java6


sudo apt-get update
sudo apt-get install sun-java6-bin sun-java6-plugin
</pre>
</pre>


== ==
== Install Lamp with 1 command ==


<pre>
<pre>
Open terminal and Type the command :install it  first  with


sudo apt-get install tasksel
Now to install LAMP, type "tasksel" in terminal :
And select LAMP Server:
During the installation  you  will be  asked  to insert the  mysql root  password
Now check if php is working :
$sudo  vi  /var/www/info.php
and add
1.
2.
phpinfo();
3.
?>
save and exit
restart apache2 ,
#sudo /etc/init.d/apache2  restart
Now open browser and type :
http://ip/info.php or http://localhost/info.php
Php is installed.
To full manage  your  lamp Server database, install  phpmyadmin
sudo  apt-get  install  phpmyadmin
To login  to phpmyadmin, open browser and type :
http://ip/phpmyadmin  or http://localhost/phpmyadmin
</pre>
</pre>


==  ==
== Remove mysql ==


<pre>
<pre>
dpkg -l | grep mysql
sudo dpkg -P –force-all <package name>


</pre>
</pre>


==  ==
== Manually install apache2, php5 mysql ==


<pre>
<pre>
sudo apt-get install apache2


sudo apt-get install php5 libapache2-mod-php5
sudo apt-get install mysql-server
6 Getting MySQL Support In PHP5
To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:
aptitude search php5
Pick the ones you need and install them like this:
aptitude install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json
Now restart Apache2:
</pre>
</pre>


== ==
== How to check Ubuntu's version ==


<pre>
<pre>
cat /etc/issue
uname -a : print all information
uname -r : print the kernel release
uname -v : print the kernel version
uname -o : print the operating system


</pre>
</pre>
== How do I find out what version of Linux distribution I'm using ==
<pre>
cat /etc/*-release


== ==
 
</pre>
== Installing Curl in ubuntu ==


<pre>
<pre>
sudo apt-get install  php5-curl
Now you have PHP cURL installed, the next thing you need to do is to restart apache2, run the following command in your terminal:


sudo /etc/init.d/apache2 restart
</pre>
</pre>


== ==
== Chmod Octal Codes ==
 
'''Permissions may be granted using human readable assignments "rwx" or octal codes. '''
 
  ''' Owner/Group/Other '''
 
 
<table border="true">
 
<tr bgcolor="#c0c0c0"><th style="font-family: helvetica, arial, sans-serif; font-weight: bold; color: #000000;">Description</th><th style="font-family: helvetica, arial, sans-serif; font-weight: bold; color: #000000;">Abreviation</th><th style="font-family: helvetica, arial, sans-serif; font-weight: bold; color: #000000;">Octal code</th></tr>
<tr>
<td>Read access</td>
<td>r</td>
<td>4</td>
</tr>
<tr>
<td>Write (change) permission</td>
<td>w</td>
<td>2</td>
</tr>
<tr>
<td>Execute script of binary executable</td>
<td>x</td>
<td>1</td>
</tr>
<tr>
<td>Read and Execute</td>
<td>rx</td>
<td>5</td>
</tr>
<tr>
<td>Read and Write</td>
<td>rw</td>
<td>6</td>
</tr>
<tr>
<td>Read, Write and Execute</td>
<td>rwx</td>
<td>7</td>
</tr>
 
</table>
 
''' Use of octal assignment does not add or remove permission, but assigns the permission explicitly.  Examples: '''
 
* Assign yourself full access to read and modify the file, allow members of the group to read it and do not allow any others access: *
 
<pre>chmod 640 filename</pre>
* Assign execute status to a script with the same access as the previous example. (Without it, a script is like any other text file)*
 
<pre>chmod 740 filename</pre>
== Modifying Ip Address in Ubuntu Terminal ==


<pre>
<pre>
sudo nano /etc/network/interfaces


Once your prefered editor opens the file you want to enter the following information (changing your addresses where necessary):
auto lo eth0
iface lo inet loopback
iface eth0 inet static
address xxx.xxx.xxx.xxx(enter your ip here)
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx(enter gateway ip here)
Be sure to save your changes.
Step 2.2 – Manually configure your dns configuration file: You can edit the appropriate file by entering the following command into the terminal:
sudo nano /etc/resolv.conf
Once your preferred editor opens the file you want to enter the following information (changing your addresses where necessary):
# Generated by NetworkManager
nameserver xxx.xxx.xxx.xxx(enter your dns server ip)
nameserver xxx.xxx.xxx.xxx(enter your alt dns server ip)
Be sure to save your changes.
Step 2.3 – Manually restart your network interface with the new settings: Enter the following command in the terminal:
sudo /etc/init.d/networking restart
This should return a result that looks like the following:
*Reconfiguring network interfaces… [OK]
At this point in your terminal you should be able to run the ifconfig command and the results should reflect your new settings. If the addressing is correct you should have full network access, even after a system restart.
</pre>
</pre>
== Uninstalling an app in shell  ==


==  ==
<pre>
sudo apt-get autoremove "appname"
 
then remove any directories that are left over
</pre>
== Ubuntu Php.ini Settings ==


<pre>
<pre>
These are lines i modify in the php.ini file to get joomla working
/etc/php5/apache2/php.ini
; Maximum size of POST data that PHP will accept.
post_max_size = 100M
; Maximum allowed size for uploaded files.
upload_max_filesize = 200M
memory_limit = 32M      ; Maximum amount of memory a script may consume (16MB)</pre>
== Setting up a network from the command Line ==
=== Network Configuration ===
Ubuntu ships with a number of graphical utilities to configure your network devices. This document is geared toward server administrators and will focus on managing your network on the command line.
=== Ethernet ===
Most Ethernet configuration is centralized in a single file, /etc/network/interfaces. If you have no Ethernet devices, only the loopback interface will appear in this file, and it will look something like this:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).


</pre>
# The loopback network interface
auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.0.0.0
If you have only one Ethernet device, eth0, and it gets its configuration from a DHCP server, and it should come up automatically at boot, only two additional lines are required:
 
auto eth0
iface eth0 inet dhcp
The first line specifies that the eth0 device should come up automatically when you boot. The second line means that interface (“iface”) eth0 should have an IPv4 address space (replace “inet” with “inet6” for an IPv6 device) and that it should get its configuration automatically from DHCP. Assuming your network and DHCP server are properly configured, this machine's network should need no further configuration to operate properly. The DHCP server will provide the default gateway (implemented via the route command), the device's IP address (implemented via the ifconfig command), and DNS servers used on the network (implemented in the /etc/resolv.conf file.)
 
To configure your Ethernet device with a static IP address and custom configuration, some more information will be required. Suppose you want to assign the IP address 192.168.0.2 to the device eth1, with the typical netmask of 255.255.255.0. Your default gateway's IP address is 192.168.0.1. You would enter something like this into /etc/network/interfaces:
 
iface eth1 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1
In this case, you will need to specify your DNS servers manually in /etc/resolv.conf, which should look something like this:
 
search mydomain.example
nameserver 192.168.0.1
nameserver 4.2.2.2
The search directive will append mydomain.example to hostname queries in an attempt to resolve names to your network. For example, if your network's domain is mydomain.example and you try to ping the host “mybox”, the DNS query will be modified to “mybox.mydomain.example” for resolution. The nameserver directives specify DNS servers to be used to resolve hostnames to IP addresses. If you use your own nameserver, enter it here. Otherwise, ask your Internet Service Provider for the primary and secondary DNS servers to use, and enter them into /etc/resolv.conf as shown above.
 
Many more configurations are possible, including dialup PPP interfaces, IPv6 networking, VPN devices, etc. Refer to man 5 interfaces for more information and supported options. Remember that /etc/network/interfaces is used by the ifup/ifdown scripts as a higher level configuration scheme than may be used in some other Linux distributions, and that the traditional, lower level utilities such as ifconfig, route, and dhclient are still available to you for ad hoc configurations.
 
=== Managing DNS Entries ===
 
This section explains how to configure which nameserver to use when resolving IP addresses to hostnames and vice versa. It does not explain how to configure the system as a name server.
 
To manage DNS entries, you can add, edit, or remove DNS names from the /etc/resolv.conf file. A sample file is given below:
 
search com
nameserver 204.11.126.131
nameserver 64.125.134.133
nameserver 64.125.134.132
nameserver 208.185.179.218
The search key specifies the string which will be appended to an incomplete hostname. Here, we have configured it to com. So, when we run: ping ubuntu it would be interpreted as ping ubuntu.com.
 
The nameserver key specifies the nameserver IP address. It will be used to resolve a given IP address or hostname. This file can have multiple nameserver entries. The nameservers will be used by the network query in the same order.
 
[Warning]
If the DNS server names are retrieved dynamically from DHCP or PPPoE (retrieved from your ISP), do not add nameserver entries in this file. It will be overwritten.
 
=== Managing Hosts ===
 
To manage hosts, you can add, edit, or remove hosts from /etc/hosts file. The file contains IP addresses and their corresponding hostnames. When your system tries to resolve a hostname to an IP address or determine the hostname for an IP address, it refers to the /etc/hosts file before using the name servers. If the IP address is listed in the /etc/hosts file, the name servers are not used. This behavior can be modified by editing /etc/nsswitch.conf at your peril.
 
If your network contains computers whose IP addresses are not listed in DNS, it is recommended that you add them to the /etc/hosts file.


== ==
== Iptables open ftp port 21 ==


<pre>
<pre>
Use iptables administration tool for IPv4 packet filtering and NAT under Linux to open tcp port 21 (FTP). Following rule-set assumes that your eth0 network interface directly connected to internet. It has public ip (202.54.1.20). FTP use both port 21 and 20 (port 21 for the command port and port 20 for the data). So following iptables rules take care of both ports (add rules to your iptables script):
Procedure


</pre>
Add support for FTP connection tracking.


==  ==
Task load required iptables modules


<pre>
First login as the root user.


</pre>
Next type the following command to load two iptables modules:
# modprobe ip_conntrack
# modprobe ip_conntrack_ftp


==  ==
Now add following iptables rules for incoming request on port 21 (open port 21) to your script:


<pre>
iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d 202.54.1.20 --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s 202.54.1.20 --sport 21 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT


</pre>
iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d 202.54.1.20 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -p tcp -s 202.54.1.20 --sport 1024:65535 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT


== ==
iptables -A OUTPUT -p tcp -s 202.54.1.20 --sport 20 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
  iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d 202.54.1.20 --dport 20 -m state --state ESTABLISHED -j ACCEPT


<pre>


</pre>
</pre>
----
==[[#Upgrading Ubuntu Server to a new release|Back To Top]]-[[Main_Page| Home]] - [[Ubuntu_Tips|Category]]==

Latest revision as of 14:54, 17 August 2016

Upgrading Ubuntu Server to a new release

  • Install update-manager-core if it is not already installed:
sudo apt-get install update-manager-core
  • Launch the upgrade tool:
sudo do-release-upgrade

Turn on Mod Rewrite

1. a2enmod rewrite 
2. restart apache server 
3. edit vhost file AllowOverride all

Apache Commands

  • List apache packages and versions
dpkg -l | grep apache
  • shows version of ubnuntu
cat /etc/issue
  • shows version of ubuntu
cat /etc/*-release
  • give detail status of the service
apachectl status
  • Gives info on where config file is located
    • apachectl -V
  • Search the entire server for the file
    • find / | grep "apache2\.conf"
  • Info for each line in the .conf File
  • Displays Config Info about all Virtual Hosts
    • apachectl -t -D DUMP_VHOSTS
  • Display All Modules form Apache
    • apachectl -t -D DUMP_MODULES
  • Enable and Disable Modules
  • Directory for Modules
    • /etc/apache2/modes-available and /etc/apache2/mods-enabled
    • a2enmod and a2dismod will enable of disable modules
  • Find where the apache error log is located
    • grep -Ri ErrorLog /etc/apache2
  • Watch Error log in realtime
    • tail -f error.log
  • Tools to Analize log files
    • AWStats - awstats.sourceforge.net
  • GoAccess - Terminal app
    • goaccess.prosoftcorp.com


Using SMTP to send email

apt-get install php-pear

pear install Mail

pear install Net_SMTP

restart apache

## you have to include this in your code.

require_once 'Mail.php';

## there is a lot more info you have to provide. do a search or pear mail

Setting up Postfix to send mail

sudo apt-get install postfix

Options

Satellite
domain.com
smtp server=  ip address or smtp.domain.com
service restart postfix

 Postfix config file
 /etc/postfix/main.cf

Giving Root Privileges to another Account

edit  /etc/sudoers.tmp

#User previlege specification

root  ALL=(ALL:ALL)ALL

#  copy the settings of the root and adapt it to your username

alex ALL=(ALL:ALL)ALL


Installing Node.js

sudo apt-get install python-software-properties

add-apt-repository ppa:chris-lea/node.js

 

apt-get update
apt-get install nodejs npm


Search Repositories

sudo apt-cache search python

will search the cached repo of all python

Changing Mac Address Linux

ifconfig wlan0 down

ifconfig wlan0 hw ether de:ad:be:ef:co:fe

ifconfig wlan0 up

ifconfig wlan0 | grep HWaddr

Repair Perl Locale Errors on Ubuntu

sudo apt-get install language-pack-en-base
sudo dpkg-reconfigure locales
if that dosent work then try this
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
apt-get install locales
dpkg-reconfigure locales

Remove Old host keys from Known_hosts

 ssh-keygen -f "/root/.ssh/known_hosts" -R 192.168.20.133

 

Sync Time with ntp server

 Using the command line, you can use dpkg-reconfigure tzdata.

dpkg-reconfigure tzdata
 
Follow instructions
 
install ntp
 
sudo apt-get install ntp

scp without password - keygen

Generate a public/private key pair on the local machine.

    ssh-keygen -t rsa
 
In response, you should see:
 
Generating public/private rsa key pair
Enter file in which to save the key ... 
 
Press Enter to accept this.
 
In response, you should see:
 
 
Enter passphrase (empty for no passphrase):
 
You don't need a passphrase, so press Enter twice.
 
In response, you should see:
 
Your identification has been saved in ... 
Your public key has been saved in ... 
 
Note the name and location of the public key just generated. It always ends in .pub.
 
Copy the public key id_rsa.pub just generated to all of your remote Linux boxes. You can use scp or FTP or whatever to make the copy. Assuming you're using root--again, see my warning in step 1--the key must be contained in the file /root/.ssh/authorized_keys. Or, if you are logging in as a user, for example, clyde, it would be in /home/clyde/authorized_keys. Notice that the authorized_keys file can contain keys from other PCs. So, if the file already exists and contains text, you need to append the contents of your public key file to what already is there
 
cat id_rsa.pub >> authorized_keys
 
The files are stored in root/.ssh
if the authorized_keys file does not exist create it and copy the id_rsa.pub from the other machine and paste in the authorized_keys file
do it for each machine so each machine has the other .pub info inthe authorized_key file
if the file already exist, just edit it and paste the other machine's .pub info.

Virtual Host Setup to display domain without the www

 Setup Virtual host so www.domain.com works and domain.com works.

ServerName www.domain.com

ServerAlias domain.com

This will allow the domain to come up with the www

Finding out Package Dependencies with apt-redepends

1 Installing apt-rdepends

apt-rdepends can be installed as follows:
 
apt-get install apt-rdepends
 
If you are on Ubuntu and are not logged in as root, use
 
sudo apt-get install apt-rdepends
 
apt-rdepends can be used as follows:
 
apt-rdepends <packagename>
 
For example, to find out all dependencies of the package wget, run:
 
apt-rdepends wget
 
For most packages, the output is even longer and might not fit on your screen. In these cases you can pipe the output into more (or less), e.g. as follows:
 
apt-rdepends apache2 | more
 
apt-rdepends apache2 | less

Set Time zone in Ubuntu Server

dpkg-reconfigure tzdata

Installing Java in Ubuntu

sudo add-apt-repository ppa:sun-java-community-team/sun-java6

sudo apt-get update
 
sudo apt-get install sun-java6-bin sun-java6-plugin
 

Install Lamp with 1 command

Open terminal and Type the command :install it   first  with

 
sudo apt-get install tasksel
Now to install LAMP, type "tasksel" in terminal :
 
And select LAMP Server:
 
During the installation  you  will be  asked  to insert the  mysql root  password
 
Now check if php is working :
 
$sudo   vi  /var/www/info.php
and add
 
1.
2.
phpinfo();
3.
?>
 
save and exit
 
restart apache2 ,
 
#sudo /etc/init.d/apache2  restart
Now open browser and type :
 
http://ip/info.php or http://localhost/info.php 
 
Php is installed.
 
To full manage  your  lamp Server database, install  phpmyadmin
 
sudo  apt-get  install  phpmyadmin
To login  to phpmyadmin, open browser and type :
 
http://ip/phpmyadmin   or http://localhost/phpmyadmin

Remove mysql

dpkg -l | grep mysql

sudo dpkg -P –force-all <package name>


Manually install apache2, php5 mysql

sudo apt-get install apache2

sudo apt-get install php5 libapache2-mod-php5

sudo apt-get install mysql-server

 
6 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

 
aptitude search php5

 
Pick the ones you need and install them like this:

 
aptitude install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json


Now restart Apache2:

How to check Ubuntu's version

cat /etc/issue

uname -a : print all information

uname -r : print the kernel release

uname -v : print the kernel version

uname -o : print the operating system

How do I find out what version of Linux distribution I'm using

cat /etc/*-release


Installing Curl in ubuntu

sudo apt-get install  php5-curl

Now you have PHP cURL installed, the next thing you need to do is to restart apache2, run the following command in your terminal:

sudo /etc/init.d/apache2 restart

Chmod Octal Codes

Permissions may be granted using human readable assignments "rwx" or octal codes.

  Owner/Group/Other 


DescriptionAbreviationOctal code
Read access r 4
Write (change) permission w 2
Execute script of binary executable x 1
Read and Execute rx 5
Read and Write rw 6
Read, Write and Execute rwx 7

Use of octal assignment does not add or remove permission, but assigns the permission explicitly.  Examples:

  • Assign yourself full access to read and modify the file, allow members of the group to read it and do not allow any others access: *
chmod 640 filename
  • Assign execute status to a script with the same access as the previous example. (Without it, a script is like any other text file)*
chmod 740 filename

Modifying Ip Address in Ubuntu Terminal

sudo nano /etc/network/interfaces

Once your prefered editor opens the file you want to enter the following information (changing your addresses where necessary):

auto lo eth0
iface lo inet loopback
iface eth0 inet static
address xxx.xxx.xxx.xxx(enter your ip here)
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx(enter gateway ip here)

Be sure to save your changes.

Step 2.2 – Manually configure your dns configuration file: You can edit the appropriate file by entering the following command into the terminal:

sudo nano /etc/resolv.conf

Once your preferred editor opens the file you want to enter the following information (changing your addresses where necessary):

# Generated by NetworkManager
nameserver xxx.xxx.xxx.xxx(enter your dns server ip)
nameserver xxx.xxx.xxx.xxx(enter your alt dns server ip)

Be sure to save your changes.

Step 2.3 – Manually restart your network interface with the new settings: Enter the following command in the terminal:

sudo /etc/init.d/networking restart

This should return a result that looks like the following:

*Reconfiguring network interfaces… [OK]

At this point in your terminal you should be able to run the ifconfig command and the results should reflect your new settings. If the addressing is correct you should have full network access, even after a system restart.

Uninstalling an app in shell

sudo apt-get autoremove "appname"

then remove any directories that are left over

Ubuntu Php.ini Settings

These are lines i modify in the php.ini file to get joomla working

/etc/php5/apache2/php.ini

; Maximum size of POST data that PHP will accept.
post_max_size = 100M

; Maximum allowed size for uploaded files.
upload_max_filesize = 200M

memory_limit = 32M      ; Maximum amount of memory a script may consume (16MB)

Setting up a network from the command Line

Network Configuration

Ubuntu ships with a number of graphical utilities to configure your network devices. This document is geared toward server administrators and will focus on managing your network on the command line.

Ethernet

Most Ethernet configuration is centralized in a single file, /etc/network/interfaces. If you have no Ethernet devices, only the loopback interface will appear in this file, and it will look something like this:

  1. This file describes the network interfaces available on your system
  2. and how to activate them. For more information, see interfaces(5).
  1. The loopback network interface

auto lo iface lo inet loopback address 127.0.0.1 netmask 255.0.0.0 If you have only one Ethernet device, eth0, and it gets its configuration from a DHCP server, and it should come up automatically at boot, only two additional lines are required:

auto eth0 iface eth0 inet dhcp The first line specifies that the eth0 device should come up automatically when you boot. The second line means that interface (“iface”) eth0 should have an IPv4 address space (replace “inet” with “inet6” for an IPv6 device) and that it should get its configuration automatically from DHCP. Assuming your network and DHCP server are properly configured, this machine's network should need no further configuration to operate properly. The DHCP server will provide the default gateway (implemented via the route command), the device's IP address (implemented via the ifconfig command), and DNS servers used on the network (implemented in the /etc/resolv.conf file.)

To configure your Ethernet device with a static IP address and custom configuration, some more information will be required. Suppose you want to assign the IP address 192.168.0.2 to the device eth1, with the typical netmask of 255.255.255.0. Your default gateway's IP address is 192.168.0.1. You would enter something like this into /etc/network/interfaces:

iface eth1 inet static address 192.168.0.2 netmask 255.255.255.0 gateway 192.168.0.1 In this case, you will need to specify your DNS servers manually in /etc/resolv.conf, which should look something like this:

search mydomain.example nameserver 192.168.0.1 nameserver 4.2.2.2 The search directive will append mydomain.example to hostname queries in an attempt to resolve names to your network. For example, if your network's domain is mydomain.example and you try to ping the host “mybox”, the DNS query will be modified to “mybox.mydomain.example” for resolution. The nameserver directives specify DNS servers to be used to resolve hostnames to IP addresses. If you use your own nameserver, enter it here. Otherwise, ask your Internet Service Provider for the primary and secondary DNS servers to use, and enter them into /etc/resolv.conf as shown above.

Many more configurations are possible, including dialup PPP interfaces, IPv6 networking, VPN devices, etc. Refer to man 5 interfaces for more information and supported options. Remember that /etc/network/interfaces is used by the ifup/ifdown scripts as a higher level configuration scheme than may be used in some other Linux distributions, and that the traditional, lower level utilities such as ifconfig, route, and dhclient are still available to you for ad hoc configurations.

Managing DNS Entries

This section explains how to configure which nameserver to use when resolving IP addresses to hostnames and vice versa. It does not explain how to configure the system as a name server.

To manage DNS entries, you can add, edit, or remove DNS names from the /etc/resolv.conf file. A sample file is given below:

search com nameserver 204.11.126.131 nameserver 64.125.134.133 nameserver 64.125.134.132 nameserver 208.185.179.218 The search key specifies the string which will be appended to an incomplete hostname. Here, we have configured it to com. So, when we run: ping ubuntu it would be interpreted as ping ubuntu.com.

The nameserver key specifies the nameserver IP address. It will be used to resolve a given IP address or hostname. This file can have multiple nameserver entries. The nameservers will be used by the network query in the same order.

[Warning] If the DNS server names are retrieved dynamically from DHCP or PPPoE (retrieved from your ISP), do not add nameserver entries in this file. It will be overwritten.

Managing Hosts

To manage hosts, you can add, edit, or remove hosts from /etc/hosts file. The file contains IP addresses and their corresponding hostnames. When your system tries to resolve a hostname to an IP address or determine the hostname for an IP address, it refers to the /etc/hosts file before using the name servers. If the IP address is listed in the /etc/hosts file, the name servers are not used. This behavior can be modified by editing /etc/nsswitch.conf at your peril.

If your network contains computers whose IP addresses are not listed in DNS, it is recommended that you add them to the /etc/hosts file.

Iptables open ftp port 21

Use iptables administration tool for IPv4 packet filtering and NAT under Linux to open tcp port 21 (FTP). Following rule-set assumes that your eth0 network interface directly connected to internet. It has public ip (202.54.1.20). FTP use both port 21 and 20 (port 21 for the command port and port 20 for the data). So following iptables rules take care of both ports (add rules to your iptables script):

Procedure

Add support for FTP connection tracking.

Task load required iptables modules

First login as the root user.

Next type the following command to load two iptables modules:
# modprobe ip_conntrack
 # modprobe ip_conntrack_ftp 

Now add following iptables rules for incoming request on port 21 (open port 21) to your script:

iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d 202.54.1.20 --dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
 iptables -A OUTPUT -p tcp -s 202.54.1.20 --sport 21 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
 

iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d 202.54.1.20 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
 iptables -A OUTPUT -p tcp -s 202.54.1.20 --sport 1024:65535 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
 

iptables -A OUTPUT -p tcp -s 202.54.1.20 --sport 20 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
 iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d 202.54.1.20 --dport 20 -m state --state ESTABLISHED -j ACCEPT



Back To Top- Home - Category