วันพฤหัสบดีที่ 15 ธันวาคม พ.ศ. 2554

Reset password root ใน mysql ของ CentOS

Reset password root ใน mysql ของ CentOS  

จดเอาไว้กันลืม สำหรับการ Restart Password ของ mysqld เวลาลงครับ
1. ให้หยุดการทำงานของ mysql ก่อน
# service mysqld stop
2. ให้ Start MySQL เป็น save mode. โดยคำสั่ง
# mysqld_safe --skip-grant-tables &
3. ต่อไปก็ให้ Login  MySQL โดย user root
# mysql -u root
4. ทำการ Update password root (ที่ขีดเส้นใต้คือให้ใส่รหัสใหม่ลงไป)
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW PASSWORD") where user='root';
mysql> flush privileges;
mysql> quit;
5. แล้วก็ restart service ของ mysql ซะ เป็นอันเรียบร้อย
# service mysqld restart
6. แล้วลองเข้าใหม่ดูครับ
# mysql -u root -p
7.พอเข้าได้แล้ว ก็ไปเข้าของ phpmyadmin เอาด้วย ก็น่าจะเข้าได้เช่นกันครับ

วันพุธที่ 2 พฤศจิกายน พ.ศ. 2554

HOW TO ADD [DAG] ON CENTOS 5 2/11/2011 :)

# Insert This Command at /etc/yum.repos.d/CentOS-Base.repo


[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://ftp.heanet.ie/pub/freshrpms/pub/dag/redhat/el5/en/i386/dag/
gpgcheck=1
enabled=1

// Save And Exit

#yum claen all
#yum list all
#yum update

Hav a fun :)

วันพุธที่ 1 มิถุนายน พ.ศ. 2554

วันจันทร์ที่ 30 พฤษภาคม พ.ศ. 2554

UPDATE [DAG] FOR smbldap-tools 30/05/2011 :>

       The default RPMforge repository does not replace any CentOS base packages. In the past it used to, but those packages are now in a separate repository (rpmforge-extras) which is disabled by default.
You can find a complete listing of the RPMforge package packages at http://packages.sw.be/
Download the rpmforge-release package. Choose one of the two links below, selecting to match your host's architecture. If you are unsure of which one to use you can check your architecture with the command uname -i
The preferred rpmforge-release package to retrieve and to install in order to enable that repository is one of the two listed above.
Install DAG's GPG key
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
Verify the package you have downloaded
rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm
<!> Security warning: The rpmforge-release package imports GPG keys into your RPM database. As long as you have verified the md5sum of the key injection package, and trust Dag, et al., then it should be as safe as your trust of them extends.
Install the package
rpm -i rpmforge-release-0.5.2-2.el5.rf.*.rpm
This will add a yum repository config file and import the appropriate GPG keys.
Then try to install something like this
yum install htop

วันเสาร์ที่ 28 พฤษภาคม พ.ศ. 2554

วิธี set iptables บน linux แบบง่ายๆ 29/05/2011

วิธี set iptables บน linux แบบง่ายๆ


ACCEPT = ยอมให้ผ่าน
DROP = ไม่สนใจแพ็กเกต
REJECT = ไม่สนใจเหมือนกัน แต่ จะแจ้งให้ เราทราบ
 
 
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j ACCEPT
iptables -A OUTPUT -p tcp -s 192.168.0.0/24 -j DROP
iptables -A OUTPUT -p tcp -d 192.168.0.0/24 -j DROP
 
 
#### ถ้าต้อง การให้ firwall ปล่อยให้ port ไหน ผ่าน ให้ เปลี่ยน ตัวเลขของ port
 
iptables -A FORWARD -p tcp -s 192.168.0.0/24 --destination-port 80 -j ACCEPT
 
iptables -A FORWARD -p tcp -d 192.168.0.0/24 --destination-port 80 -j ACCEPT
 
 
#### Block MSN
iptables -A INPUT -p tcp -s 192.168.0.0/24 --destination-port 1836 -j DROP
iptables -A INPUT -p tcp -d 192.168.0.0/24 --destination-port 1836 -j DROP
iptables -A FORWARD -p tcp -s 192.168.0.0/24 --destination-port 1836 -j DROP
iptables -A FORWARD -p tcp -d 192.168.0.0/24 --destination-port 1836 -j DROP

Have a fun... :-)

วันพุธที่ 18 พฤษภาคม พ.ศ. 2554

Setup Samba / OpenLDAP on CentOS 08 May 2011

Samba / OpenLDAP on CentOS

Samba will serve three main purposes:
  • Act as a Primary Domain Controller for Windows clients
  • Serve the network printers to Windows clients
  • Serve files to Windows and Linux clients
To act as a primary domain controller, Samba needs to access LDAP as the central authentication database.
Install Samba
yum install samba nscd
Load the Samba schema file into LDAP on the LDAP server.
It is located at /usr/share/doc/samba-3.0.28/LDAP/samba.schema on the Samba server.
Configure LDAP for Samba
We need to create the default organisational units for Samba so while log into phpldapadmin (assumed already installed), expand the root node and then click on:
Create new entry here
Select Organisational Unit and click Proceed.
Enter the information:
Organisational Unit -> users
and click Proceed
  • NOTE: If Proceed is still greyed out, hit the ‘Tab’ key.
Now select Create Object to finally create it.
Repeat these three steps to create another two organisational units called:
groups
and
machines
Configure Samba for LDAP
To tell Samba to use LDAP database back end:
Stop Samba:
service samba stop
Open up /etc/samba/smb.conf and search for:
passdb backend = tdbsam
Delete that line and replace with:
passdb backend = ldapsam:ldap://IP address of LDAP server
ldap suffix = dc=simonandkate,dc=lan
ldap machine suffix = ou=machines
ldap user suffix = ou=users
ldap group suffix = ou=groups
ldap admin dn = cn=Manager,dc=simonandkate,dc=lan
ldap delete dn = no
Samba has now been told to use LDAP. Now we need to tell Samba to act as a primary domain controller.
Still in the /etc/samba/smb.conf file, ensure that the following are set:
wins support = yes
name resolve order = lmhosts host wins bcast
security = user
domain logons = yes
domain master = auto
Add the following items (you should check to make sure they are not already there):
ldap password sync = yes
enable privileges = yes
preferred master = auto
local master = yes
This tells Samba to act as the primary domain controller for the network.
Now we need to ensure other components of running a primary domain controller exist, such as the profiles shares and logon paths.
Ensure that the following are set (make sure the paths are exactly as specified):
logon path = \\%N\profiles
logon drive = H:
logon home = \\%N\%U\data
logon script = logon.bat
The value %N is the netbios name of the server, %U is the Windows username. This means the logon path will be set to the profiles share from the server. The profiles share from the server (as you will see shortly) is actually a directory under the user’s home location called the profiles (and thus unique for each user). Similarly, the H:\ will be automatically mapped to the data directory in the user’s home location. Later we will make sure that these folders exist on the server.
  • NOTE: If you want to give users individual logon scripts you can do so by changing logon script to:
logon script = %S.bat
Next, make sure that the Samba shares are configured. Here, %S is the Unix account, so the home share is on the physical directory /home/[username]/data/ on the server (this is what the H:\ is mapped to above).
See http://oreilly.com/catalog/samba/chapter/book/ch06_06.html for useful information on Logon scripts.
Edit the shares to look like this (once again, make sure the paths are exactly as specified):
[homes]
  comment = Home Directories
  browseable = no
  path = /home/%S/data
  valid users = %S
  writable = yes
  create mask = 0600
  directory mask = 0700

[netlogon]
  comment = Network Logon Service
  path = /data/samba/netlogon
  guest ok = yes
  writable = no
  share modes = no
  write list = @admins

[profiles]
  comment = Users profiles
  path = /home/%U/profiles
  guest ok = no
  browseable = no
  create mask = 0600
  directory mask = 0700
  writable = yes
We store each user’s profile and data under their home directory. All other group information and shares are stored under the /data/samba/ directory.
When you have finished, save and exit the file.
Samba should now be configured as a primary domain controller, set to use LDAP and has the required shares enabled.
Before we restart Samba, let’s check its configuration with
testparm
You should see output something like this
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[netlogon]"
Processing section "[profiles]"
Processing section "[printers]"
Processing section "[print$]"
Loaded services file OK.
Server role: ROLE_DOMAIN_PDC
Press enter to see a dump of your service definitions
This (should) tell you there were no errors and that the server’s role is as primary domain controller.
Set Samba LDAP Admin Password
Very importantly, we need to tell Samba the password for our LDAP admin account so that it can do fancy stuff. It sets the password for the LDAP account specified above in the smb.conf (cn=Manager,dc=simonandkate,dc=lan), so make sure that’s all correct.
To set the password, simply run:
smbpasswd -w [ldap admin password]
http://blog.simonandkate.net/20091230/samba-openldap-on-centos
Have a fun...  ;)

Task: Disable / Turn off Linux Firewall (Red hat/CentOS/Fedora Core) 08 May 2011

Type the following two commands (you must login as the root user):
# /etc/init.d/iptables save
# /etc/init.d/iptables stop

Task: Enable / Turn on Linux Firewall (Red hat/CentOS/Fedora Core)

Type the following command to turn on iptables firewall:
# /etc/init.d/iptables start

          Have a fun......:-)

วันอาทิตย์ที่ 10 เมษายน พ.ศ. 2554

How to use sudo. (10 April 2011)

 root # vi /etc/sudoers

So, here's a simple /etc/sudoers file (remember, edit with "visudo") to give "admin" access to root commands.

______________________________________________

# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.


# User privilege specification
root    ALL=(ALL) ALL
admin    ALL=(ALL)       ALL    # user name admin
 
# Edit user or add user and set same values by over line. but you have to change name user.
_______________________________________________________________
 
How to use it.Example.
root..#yum -y install httpd   
sudo....# sudo yum -y install httpd  
promp....(password).....
How to switch to root!
sudo....# sudo su -
promp....(password)....
***************************************
that's work same "root".

_/|\_ 23:36
 

วันเสาร์ที่ 9 เมษายน พ.ศ. 2554

How to install FTP on centos 5.5 ( 9 April 2011 ) Update :D


the standard CentOS packages seem to be vsftp and proftp.
   # yum list installed | grep ftp
if you did not install the ftp package during installation, you will need to install vsftp
   # yum install vsftp
You will also want to enable vsftp on start-up, so
   # chkconfig vsftpd on
And start service vsftpd 
   # service vsftp start
configure it in /etc/vsftp/vstpd.conf
   # vi  /etc/vsftp/vstpd.conf

 It works now   :)

วันพฤหัสบดีที่ 7 เมษายน พ.ศ. 2554

Basic linux commands ( 7 April 2011 )

Basic linux commands :b

mkdir - make directories
Usage
mkdir [OPTION] DIRECTORY
Options
Create the DIRECTORY(ies), if they do not already exist.
 Mandatory arguments to long options are mandatory for short options too.
 -m, mode=MODE  set permission mode (as in chmod), not rwxrwxrwx - umask
 -p, parents  no error if existing, make parent directories as needed
 -v, verbose  print a message for each created directory
 -help display this help and exit
 -version output version information and exit
cd - change directories
Use cd to change directories. Type cd followed by the name of a directory to access that directory.Keep in mind that you are always in a directory and can navigate to directories hierarchically above or below.
mv- change the name of a directory
Type mv followed by the current name of a directory and the new name of the directory.
 Ex: mv testdir newnamedir
pwd - print working directory
will show you the full path to the directory you are currently in. This is very handy to use, especially when performing some of the other commands on this page
 rmdir - Remove an existing directory
 rm -r
Removes directories and files within the directories recursively.
chown - change file owner and group
Usage
chown [OPTION] OWNER[:[GROUP]] FILE
chown [OPTION] :GROUP FILE
chown [OPTION] --reference=RFILE FILE
Options
Change the owner and/or group of each FILE to OWNER and/or GROUP. With --reference, change the owner and group of each FILE to those of RFILE.
 -c, changes like verbose but report only when a change is made
 -dereference affect the referent of each symbolic link, rather than the symbolic link itself
 -h, no-dereference affect each symbolic link instead of any referenced file (useful only on systems that can         change the ownership of a symlink)
 -from=CURRENT_OWNER:CURRENT_GROUP
  change the owner and/or group of each file only if its current owner and/or group match those specified here.  Either  may  be  omitted,  in which case a match is not required for the omitted attribute.
-no-preserve-root do not treat `/' specially (the default)
-preserve-root fail to operate recursively on `/'
-f, -silent, -quiet  suppress most error messages
-reference=RFILE use RFILE's owner and group rather than the specifying OWNER:GROUP values
-R, -recursive operate on files and directories recursively
-v, -verbose output a diagnostic for every file processed
The  following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one  takes effect.
-H     if a command line argument is a symbolic link to a directory, traverse it
-L     traverse every symbolic link to a directory encountered
-P     do not traverse any symbolic links (default)
chmod - change file access permissions
Usage
chmod [-r] permissions filenames
 r  Change the permission on files that are in the subdirectories of the directory that you are currently in.        permission  Specifies the rights that are being granted. Below is the different rights that you can grant in an alpha  numeric format.filenames  File or directory that you are associating the rights with Permissions
u - User who owns the file.
g - Group that owns the file.
o - Other.
a - All.
r - Read the file.
w - Write or edit the file.
x - Execute or run the file as a program.
Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:
400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody
ls - Short listing of directory contents
-a        list hidden files
-d        list the name of the current directory
-F        show directories with a trailing '/'
            executable files with a trailing '*'
-g        show group ownership of file in long listing
-i        print the inode number of each file
-l        long listing giving details about files  and directories
-R        list all subdirectories encountered
-t        sort by time modified instead of name
cp - Copy files
cp  myfile yourfile
Copy the files "myfile" to the file "yourfile" in the current working directory. This command will create the file "yourfile" if it doesn't exist. It will normally overwrite it without warning if it exists.
cp -i myfile yourfile
With the "-i" option, if the file "yourfile" exists, you will be prompted before it is overwritten.
cp -i /data/myfile
Copy the file "/data/myfile" to the current working directory and name it "myfile". Prompt before overwriting the  file.
cp -dpr srcdir destdir
Copy all files from the directory "srcdir" to the directory "destdir" preserving links (-poption), file attributes (-p option), and copy recursively (-r option). With these options, a directory and all it contents can be copied to another dir
ln - Creates a symbolic link to a file.
ln -s test symlink
Creates a symbolic link named symlink that points to the file test Typing "ls -i test symlink" will show the two files are different with different inodes. Typing "ls -l test symlink" will show that symlink points to the file test.
locate - A fast database driven file locator.
slocate -u
This command builds the slocate database. It will take several minutes to complete this command.This command must be used before searching for files, however cron runs this command periodically  on most systems.locate whereis Lists all files whose names contain the string "whereis". directory.
more - Allows file contents or piped output to be sent to the screen one page at a time
less - Opposite of the more command
cat - Sends file contents to standard output. This is a way to list the contents of short files to the screen. It works well with piping.
whereis - Report all known instances of a command
wc - Print byte, word, and line counts
bg
bg jobs Places the current job (or, by using the alternative form, the specified jobs) in the background, suspending its execution so that a new user prompt appears immediately. Use the jobs command to discover the identities of background jobs.
cal month year - Prints a calendar for the specified month of the specified year.
cat files - Prints the contents of the specified files.
clear - Clears the terminal screen.
cmp file1 file2 - Compares two files, reporting all discrepancies. Similar to the diff command, though the output format differs.
diff file1 file2 - Compares two files, reporting all discrepancies. Similar to the cmp command, though the output format differs.
dmesg - Prints the messages resulting from the most recent system boot.
fg
fg jobs - Brings the current job (or the specified jobs) to the foreground.
file files - Determines and prints a description of the type of each specified file.
find path -name pattern -print
Searches the specified path for files with names matching the specified pattern (usually enclosed in single quotes) and prints their names. The find command has many other arguments and functions; see the online documentation.
finger users - Prints descriptions of the specified users.
free  - Displays the amount of used and free system memory.
ftp hostname
Opens an FTP connection to the specified host, allowing files to be transferred. The FTP program provides subcommands for accomplishing file transfers; see the online documentation.
head files - Prints the first several lines of each specified file.
ispell files - Checks the spelling of the contents of the specified files.
kill process_ids
kill - signal process_ids
kill -l
Kills the specified processes, sends the specified processes the specified signal (given as a number or name), or prints a list of available signals.
killall program
killall - signal program
Kills all processes that are instances of the specified program or sends the specified signal to all processes that are instances of the specified program.
mail - Launches a simple mail client that permits sending and receiving email messages.
man title
man section title - Prints the specified man page.
ping host - Sends an echo request via TCP/IP to the specified host. A response confirms that the host is operational.
reboot - Reboots the system (requires root privileges).
shutdown minutes
shutdown -r minutes
Shuts down the system after the specified number of minutes elapses (requires root privileges). The -r option causes the system to be rebooted once it has shut down.
sleep time - Causes the command interpreter to pause for the specified number of seconds.
sort files - Sorts the specified files. The command has many useful arguments; see the online documentation.
split file - Splits a file into several smaller files. The command has many arguments; see the online documentation
sync - Completes all pending input/output operations (requires root privileges).
telnet host - Opens a login session on the specified host.
top - Prints a display of system processes that's continually updated until the user presses the q key.
traceroute host - Uses echo requests to determine and print a network path to the host.
uptime - Prints the system uptime.
w - Prints the current system users.
wall - Prints a message to each user except those who've disabled message reception. Type Ctrl-D to end the message.