≡ Menu

Some Useful Linux Shell Commands

Shell is a program that connects users with the operating system in this case the kernel (core operating system), generally provides a shell prompt as the user interface, where users had fed the desired commands in the form of an internal shell command (internal command), or command execution of a program file (external command), but it allows the user formulate a set of shell commands on one or more files to be executed as a program.

Unlike other operating systems that only provide 1 or 2 shell, Unix family of operating systems such as Linux until recently complemented by the many shell with a collection of commands that very much, allowing the user to choose the shell where the most good to help get the job done, or can be Also moving from one shell to another shell that easily,

If you are new to shell (SSH), below are some commands to get you started. A full list of shell commands can be found here http://www.oreillynet.com/linux/cmd/

Some useful commands are:

cd /home/
Will change directory to the /home directory

top
This shows basic information such as uptime, cpu usage, memory usage and processes running.

ls
List all files in a directory.

ls -al
List all files plus hidden files.

ls -alh
List all files and hidden files and display the file size in an easier format.

ps -aux
Show all processes running.

netstat -natp
Show all active tcp connections to your server.

netstat -naup
Show all active udp connections to your server.

tail filename
Show the end contents of a file. This is good for viewing last entries to log files.

who
Show who is logged into shell.

last
Show a list of all accesses to the server ftp and shell.

pwd
shows your current position in the filesystem

locate expression
Will find all files named with ‘expression’

find . -type f -exec fgrep -li happy {} ;
Will list all files in the current directory that contain the word ‘happy’

chown username.group file.txt
Will change the ownership of file.txt to user ‘username and group ‘group’

chmod 755 file.cgi
Will change the permissions on file.cgi

cp file.txt file2.txt
Copies file.txt to file2.txt

rm file.txt
Deletes file.txt

who
List the users logged in on the machine. —

rwho -a
List all users logged in on your network. The rwho service must be enabled for this command to work.

finger user_name
System info about a user. Try: finger root last. This lists the users last logged-in on your system.

history | more
Show the last (1000 or so) commands executed from the command line on the current account. The | more causes the display to stop after each screen fill.

pwd
Print working directory, i.e. display the name of your current directory on the screen.

hostname
Print the name of the local host (the machine on which you are working).

whoami
Print your login name.

id username
Print user id (uid) and his/her group id (gid), effective id (if different than the real id) and the supplementary groups.

date
Print or change the operating system date and time. E.g., change the date and time to 2000-12-31 23:57 using this command

date 123123572000
To set the hardware clock from the system clock, use the command (as root)

setclock

time
Determine the amount of time that it takes for a process to complete+ other info. Don’t confuse it with date command. For e.g. we can find out how long it takes to display a directory content using time ls

uptime
Amount of time since the last reboot

ps
List the processes that are have been run by the current user.

ps aux | more
List all the processes currently running, even those without the controlling terminal, together with the name of the user that owns each process.

top
Keep listing the currently running processes, sorted by cpu usage (top users first).

uname -a
Info on your server.

free
Memory info (in kilobytes).

df -h
Print disk info about all the file systems in a human-readable form.

du / -bh | more
Print detailed disk usage for each subdirectory starting at root (in a human readable form).

lsmod
(as root. Use /sbin/lsmod to execute this command when you are a non-root user.) Show the kernel modules currently loaded.

set|more
Show the current user environment.

echo $PATH
Show the content of the environment variable PATH. This command can be used to show other environment variables as well. Use set to see the full environment.

dmesg | less
Print kernel messages (the current content of the so-called kernel ring buffer). Press q to quit less. Use less /var/log/dmesg to see what dmesg dumped into the file right after bootup. – only works on dedciated systems

Commands for Process control
ps
Display the list of currently running processes with their process IDs (PID) numbers. Use ps aux to see all processes currently running on your system (also those of other users or without a controlling terminal),
each with the name of the owner. Use top to keep listing the processes currently running.

fg
PID Bring a background or stopped process to the foreground.

bg
PID Send the process to the background. This is the opposite of fg. The same can be accomplished with Ctrl z

any_command &
Run any command in the background (the symbol means run the command in the background?).

kill PID
Force a process shutdown. First determine the PID of the process to kill using ps.

killall -9 program_name
Kill program(s) by name.

xkill
(in an xwindow terminal) Kill a GUI-based program with mouse. (Point with your mouse cursor at the window of the process you want to kill and click.)

lpc
(as root) Check and control the printer(s). Type ??? to see the list of available commands.

lpq
Show the content of the printer queue.

lprm job_number
Remove a printing job job_number from the queue.

nice program_name
Run program_name adjusting its priority. Since the priority is not specified in this example, it will be adjusted by 10 (the process will run slower), from the default value (usually 0). The lower the number (of niceness to other users on the system), the higher the priority. The priority value may be in the range -20 to 19. Only root may specify negative values. Use top to display the priorities of the running processes.

renice -1 PID
(as root) Change the priority of a running process to -1. Normal users can only adjust processes they own, and only up from the current value (make them run slower).

exit
Logs you out of shell.

I hope this Linux Shell Commands can be useful for you all

{ 1 comment }

virtual private server vpsTutorials following continued discussions from How to Secure and Optimize a Server or VPS part 1

=========================================
Install BFD (Brute Force Detection – optional)
=========================================

To install BFD, SSH into server and login as root.

At command prompt type:

After BFD has been installed, you need to edit the configuration file.

At command prompt type:

Under Enable brute force hack attempt alerts:
Find

and change it to

Find

and change it to

Save the changes then exit.

To start BFD

At command prompt type:

Modify LogWatch

Logwatch is a customizable log analysis system. It parses through your system’s logs for a given period of time and creates a report analyzing areas that you specify, in as much detail as you require. Logwatch is already installed on most CPanel servers.

To modify LogWatch, SSH into server and login as root.

At command prompt type:

Scroll down to

and change to

[note]
Note: Set the e-mail address to an offsite account incase you get hacked.
[/note]
Now scroll down to

Change that to Medium, or High…

[note]
Note: High will give you more detailed logs with all actions.
[/note]
Save and exit.

A number of suggestions to improve system security. Some of this is specific to CPanel, but much can be applied to most Linux systems.
[info]
Use The Latest Software
Keep the OS and 3rd party software up to date. Always!
CPanel itself can be updated from the root WHM.
[/info]
Change Passwords

Change the root passwords at least once a month and try to make them hard to guess. Yes it’s a pain to have to keep remembering them, but it’s better than being hacked.

————————————————–
Set Up A More Secure SSH Environment As described here.
————————————————–

Disable Telnet
1. Type: pico -w /etc/xinetd.d/telnet
2. Change the disable = no line to disable = yes.
3. Hit CTRL+X press y and then enter to save the file.
4. Restart xinted with: /etc/rc.d/init.d/xinetd restart
Also, add the following line to /etc/deny.hosts to flag Telnet access attempts as ’emergency’ messages.

in.telnetd : ALL : severity emerg

————————————————–
Disable Unnecessary Ports (optional)
First backup the file that contains your list of ports with:

Now configure /etc/services so that it only has the ports you need in it. This will match the ports enabled in your firewall.
On a typical CPanel system it would look something like this:

Additional ports are controlled by /etc/rpc. These aren’t generally needed, so get shot of that file with: mv /etc/rpc /etc/rpc-moved
————————————————–
Watch The Logs
Install something like logwatch to keep an eye on your system logs. This will extract anything ‘interesting’ from the logs and e-mail to you on a daily basis.
Logwatch can be found at: http://www.logwatch.org
Install instructions here.
————————————————–
Avoid CPanel Demo Mode
Switch it off via WHM Account Functions => Disable or Enable Demo Mode.
————————————————–
Jail All Users
Via WHM Account Functions => Manage Shell Access => Jail All Users.
Better still never allow shell access to anyone – no exceptions.
————————————————–
Immediate Notification Of Specific Attackers
If you need immediate notification of a specific attacker (TCPWrapped services only), add the following to /etc/hosts.deny

Replacing nnn.nnn.nnn.nnn with the attacker’s IP address.
Replacing hostname with your hostname.
Replacing notify@mydomain.com with your e-mail address.
This will deny access to the attacker and e-mail the sysadmin about the access attempt.
————————————————–

Check Open Ports

From time to time it’s worth checking which ports are open to the outside world. This can be done with:

If nmap isn’t installed, it can be selected from root WHM’s Install an RPM option.
————————————————–

Set The MySQL Root Password

This can be done in CPanel from the root WHM Server Setup -> Set MySQL Root Password.
Make it different to your root password!
————————————————–
Tweak Security (CPanel)

From the root WHM, Server Setup -> Tweak Security, you will most likely want to enable:
– php open_basedir Tweak.
– SMTP tweak.
You may want to enable:
– mod_userdir Tweak. But that will disable domain preview.
————————————————–

Use SuExec (CPanel)
From root WHM, Server Setup -> Enable/Disable SuExec. This is CPanel’s decription of what it does:
“suexec allows cgi scripts to run with the user’s id. It will also make it easier to track which user has sent out an email. If suexec is not enabled, all cgi scripts will run as nobody. ”
Even if you don’t use phpsuexec (which often causes more problems), SuExec should be considered.
————————————————–

Use PHPSuExec (CPanel)
This needs to built into Apache (Software -> Update Apache from the root WHM) and does the same as SuExec but for PHP scripts.
Wisth PHPSuExec enabled, you users will have to make sure that all their PHP files have permissions no greater than 0755 and that their htaccess files contain no PHP directives.
————————————————–

Disable Compilers
This will prevent hackers from compiling worms, root kits and the like on your machine.
To disable them, do the following:

You will need to enable them again when you need to perform system updates. To do this, run:

————————————————–

Obfuscate The Apache Version Number

1. Type: pico /etc/httpd/conf/httpd.conf
2. Change the line that begins ServerSignature to:

3. Add a line underneath that which reads:

4. Hit CTRL+X, they y, the enter to save the file.
5. Restart Apache with:

——————–

So I’ve mentioned how we are to How to Secure and Optimize a Server or VPS

{ 0 comments }

virtual private server vpsWhen you have a Dedicated Server or Virtual Private Server (VPS) security issues and optimization of a server is a necessity that must be considered by a sysadmin. Here I have to say a few ways that can be used to secure and optimize a Dedicate server or Virtual Private Server (VPS).

=========================================
Checking for formmail
=========================================

Form mail is used by hackers to send out spam email, by relay and injection methods.

Command to find pesky form mails:

CGIemail is also a security risk:

Command to disable form mails:

(a-rwx translates to all types, no read, write or execute permissions).

(this disables all form mail)

If a client or someone on your vps installs form mail, you will have to let them know you are disabling their script and give them an alternative.

=========================================
Root kit checker – http://www.chkrootkit.org/
=========================================

Check for root kits and even set a root kit on a cron job. This will show you if anyone has compromised your root. Always update chrootkit to get the latest root kit checker. Hackers and spammers will try to find insecure upload forms on your box and then with injection methods, try to upload the root kit on your server. If he can run it, it will modify many files, possibly causing you to have to reinstall.

To install chrootkit, SSH into server and login as root.
At command prompt type:

To run chkrootkit

At command prompt type:

Make sure you run it on a regular basis, perhaps including it in a cron job.

Execution

I use these three commands the most.

=========================================
Install a root breach DETECTOR and EMAIL WARNING
=========================================

If someone does happen to get root, be warned quickly by installing a detector and warning at your box. You will at least get the hackers/spammers ip address and be warned someone is in there.

Server e-mail everytime someone logs in as root

To have the server e-mail you everytime someone logs in as root, SSH into server and login as root.

At command prompt type:

Scroll down to the end of the file and add the following line:

Save and exit.

Set an SSH Legal Message

To an SSH legal message, SSH into server and login as root.

At command prompt type:

Enter your message, save and exit.

=========================================
Web Host manager and CPANEL mods.
=========================================

These are items inside of WHM/Cpanel that should be changed to secure your server.

Goto Server Setup =>> Tweak Settings
Check the following items…

Under Domains
Prevent users from parking/adding on common internet domains. (ie hotmail.com, aol.com)

Under Mail
Attempt to prevent pop3 connection floods
Default catch-all/default address behavior for new accounts – blackhole

Under System
Use jailshell as the default shell for all new accounts and modified accounts

Goto Server Setup =>> Tweak Security
Enable php open_basedir Protection
Enable mod_userdir Protection
Disabled Compilers for unprivileged users.

Goto Server Setup =>> Manage Wheel Group Users
Remove all users except for root and your main account from the wheel group.

Goto Server Setup =>> Shell Fork Bomb Protection
Enable Shell Fork Bomb/Memory Protection

When setting up Feature Limits for resellers in Resellers =>> Reseller Center, under Privileges always disable Allow Creation of Packages with Shell Access and enable Never allow creation of accounts with shell access; under Root Access disable All Features.

Goto Service Configuration =>> FTP Configuration
Disable Anonymous FTP

Goto Account Functions =>> Manage Shell Access
Disable Shell Access for all users (except yourself)

Goto Mysql =>> MySQL Root Password
Change root password for MySQL

Goto Security and run Quick Security Scan and Scan for Trojan Horses often. The following and similar items are not Trojans:

=========================================
More Security Measures
=========================================

These are measures that can be taken to secure your server, with SSH access.

Update OS, Apache and CPanel to the latest stable versions.
This can be done from WHM/CPanel.

Restrict SSH Access
To restrict and secure SSH access, bind sshd to a single IP that is different than the main IP to the server, and on a different port than port 22.

SSH into server and login as root.
Note: You can download Putty by Clicking Here (http://www.chiark.greenend.org.uk/~s…/download.html). It’s a clean running application that will not require installation on Windows-boxes.

At command prompt type:

Scroll down to the section of the file that looks like this:

Uncomment and change

Uncomment and change

Uncomment and change

Note 1: If you would like to disable direct Root Login, scroll down until you find

Save by pressing Ctrl o on your keyboard, and then exit by pressing Ctrl x on your keyboard.

Note 2: You can also create a custome nameserver specifically for your new SSH IP address. Just create one called something like ssh.xyz.com. Be sure to add an A address to your zone file for the new nameserver.

Now restart SSH
At command prompt type:

Exit out of SSH, and then re-login to SSH using the new IP or nameserver, and the new port.
[note]
Note: If you should have any problems, just Telnet into your server, fix the problem, then SSH in again. Telnet is a very unsecure protocol, so change your root password after you use it.
[/note]
After SSH has been redirected, disable telnet.

Disable Telnet
To disable telnet, SSH into server and login as root.
At command prompt type:

change disable = no to disable = yes
Save and Exit
At command prompt type:

Disable Shell Accounts
To disable any shell accounts hosted on your server SSH into server and login as root.
At command prompt type:

Also check for:

[note]
Note: There will be several listings that will be OS/CPanel related. Examples are
[/note]

etc.

Disable identification output for Apache

(do this to hide version numbers from potentional hackers)

To disable the version output for proftp, SSH into server and login as root.
At command prompt type:

Scroll (way) down and change the following line to

Restart Apache

At command prompt type:

This tutorial will be continued to part 2 – How to Secure and Optimize a Server or VPS – 2

{ 0 comments }

Have heard the news that Windows 8 will appear, but we still do not know when it will appear, well here I will share how to install a Windows 8 transformation pack for windows 7.

Steps:

1. Open links:
http://deepxw.blogspot.com/2008/11/universal-theme-patcher.html
select the 3rd link (which is click to download) because the other link is broken and then extract the file

2. Before you open the patch here, there are 2 folders, x64 and x86.
x64 means 64bit and x86 means 32 which fit with your system ..

3. Open one of them (which is x64 or x86) and click yes. And then there will be a menu with 3 options, click the patch to all. Patch to completion

4. After patch, download link:
http://www.mediafire.com/?lnv5xbtp4c6i6cn
which contains the theme and the rest

5. Extract and then open, you all will see 3 logos, windows32, themes and windows

6. First, open the windows 8 theme. End then block floating windows folders and 8 floating themes
copy/paste into c:/windows/Resources/Themes
double click the windows 8 floating theme that you paste, theme windows 8 will be active.

CAUTION:

IF YOU DO NOT WANT THERE IS THE POSSIBILITY OF COMPUTER BROKEN, JUST STOP HERE. BUT IF WANT TO STAY UP WITH THE PERFECT THEME, DO WITH YOUR OWN RISK

7. OPEN SYSTEM32 folder in the file has been downloaded earlier, and then open

c/windows/system32

then find imageres.dll

then right click, select properties, go to the Security tab.
click advanced, then the owner tab and edit. Then click your username and click OK. And then click ok. Click edit in the Properties window, click your username and click full control

8. After that, rename imageres.dll was so imageres.dll.old (for backup) and then copy imageres.dll from the folder where the download window 8 themes

9. Go to c / windows and search for explorer.exe.
Once found, right click and do the same thing to imageres.dll earlier.
explorer.exe.old then rename the copy explorer.exe from the folder downloaded earlier.

10. Remember the logon screen from where we downloaded earlier?
Was useless so we need to download the new:
http://www.mediafire.com/?znozy2erjkn

11. After finished, lagi2 go to c:/windows/system32 , find
ExplorerFrame.dll do the same thing as to imageres.dll and explorer.exe.
then rename it so ExplorerFrame.dll.old
Copy/paste ExplorerFrame.dll which we downloaded earlier.

12. last: Restart your computer, then see what happens!

What changed: Theme, START ORB, TRANSPARENT WINDOWS EXPLORER, and BUTTON FRONT AND REAR WINDOWS EXPLORER

If you want to implemented my tutorial about how to install a Windows 8 transformation pack for windows 7 DO WITH YOUR OWN RISK

{ 0 comments }

Clean tmpDSK with tmpwatch

When you use cache modules such as memcache, xcache, eAccelerator and others on your cpanel server, then the modules would be very wasteful consuming temporary space from your servers.

One way to clear the cache in tmpDSK that are not used within a certain time is to use tmpwatch. Here’s an example of using tmp watch that at the store in the crontab:

Rare-steps are as follows:

Meaning of crontab command above is the server will clear the cache in tmpDSK that are not in use within 24 hours and orders to remove it will be repeated every 1 hour

The question now, whether it is safe for your server? the answer, I do it and never felt there was a problem

{ 2 comments }

Some time ago I had found the debate on the WHT (webhostingtalk) who said CloudLinux is not an Operating System, but it CloudLinux is Centos-Based Operating System.

The debate starts from the understanding that CloudLinux just run the script to limit the process to get the same rations, which meant of course LVe is the division based on virtual spaces. but this debate directly through Cloud briefly as CEO of Linux itself directly provide the answer to that understanding.

Iseletsky said:

CloudLinux is an OS/Linux distribution. It uses specialized process scheduler to limit amount of resources available to group of processes.
#1. We are not dependent on process running as user. We can limit mod_php
#2. We don’t calculate / add up resources used up by processes — as this is VERY EXPENSIVE and will not work once your load is high (your process to calculate the usage will not have CPU resources to actually perform its calculations/do anything about it).
#3 It is not like 1H Hive. 1H Hive uses basic ulimits — you can achieve same results as 1H Hive by putting RLimitNProc/RLimitCPU/etc. into apache config (which are available to anyone on CentOS). This is all based on per process information. CloudLinux works with group of processes — making sure that usage is calculated for all of them together, not for one of them.

ebook store

{ 0 comments }