+ Reply to Thread
Results 1 to 1 of 1
Thread: SSH commands
-
Some SSH commands to use while on your dedicated server!
pwd Shows the full path of the current directory
Moving, Copying and Deleting FilesCode:ls Lists all the files in the current directory ls -al Lists all files and information ls –alR Lists all files and information in all subdirectories ls -alR | more Same as ls –alR, pausing when screen becomes full ls -alR > filename.txt Same as ls –alR, outputs the results to a file ls *.html Lists all files ending with .html cd [directory name] Changes to a new directory cd .. Changes to directory above current one clear Clears the screen vdir Gives a more detailed listing than the "ls" command exit Log off your shell
Creating, Moving, Copying and Deleting DirectoriesCode:mv [old filename] [new filename] Move/rename a file cp [filename] [new filename] Copies a file rm [filename] Deletes a file rm * Deletes all files in current directory rm *.html Deletes all files ending in .html rm -rf [directoryname] delete a directory
Searching Files and DirectoriesCode:mkdir [directory name] Creates a new directory ls -d */ Lists all directories within current directory cp -r [directory] [new directory] Copies a directory and all files/directories in it
File and Directory PermissionsCode:find . -name [filename] -print Searches for a file starting with current directory grep [text] [filename] Searches for text within a file
How do i tar a file?Code:There are three levels of file permissions: read, write and execute. In addition, there are three groups to which you can assign permissions: file owner, user group and everyone. The command chmod followed by three numbers is used to change permissions. The first number is the permission for the owner, the second for the group and the third for everyone. Here are how the levels of permission translate: 0 = --- No permission 1 = --X Execute only 2 = -W- Write only 3 = -WX Write and execute 4 = R-- Read only 5 = R-X Read and execute 6 = RW- Read and write 7 = RWX Read, write and execute It is preferred that the group always have permission of 0. This prevents other users on the server from browsing files via Telnet and FTP. Here are the most common file permissions used: chmod 604 [filename] Minimum permissions for HTML file chmod 705 [directory name] Minimum permissions for directories chmod 755 [filename] Minimum permissions for scripts & programs chmod 606 [filename] Permissions for data files used by scripts chmod 703 [directory name] Write-only permissions for public FTP uploading
How do i untar a file?Code:tar cvzf filename.tar.gz filename
How do I unzip a file with telnet?Code:tar zxvf depo.tar.gz
Backing up, restore, zip, unzip DBCode:All of the below commands assume that you are within the same directory that the compressed file is in. To be sure type: ls {enter} If the file is there, you're ready to go. If not type: cd /big/dom/xdomain/www/directory/ {enter} replacing the path with the correct path to your file. If a file ends in .zip (for example, file.zip) type: unzip file.zip If a file ends in .tar (e.g., file.tar) type: tar -xvf file.tar If a file ends in .gz (for example, file.gz) type: gzip -d file.gz If a file ends in .tar.gz (e.g. file.tar.gz) type: gzip -d file.tar.gz and then tar -xvf file.tar If a file ends in .tgz (e.g. file.tgz)
If you need to backup a single cPanel account, and don't want to do it through the web interface of cPanel you can do it through SSH. There is a script in the /scripts directory on cPanel webservers called "pkgacct"Code:backing up : mysqldump -u db_usr_name -pPASSWORD db_name > file name.SQL restore : mysqll -u db_usr_name -pPASSWORD db_name < file name.SQL zip it : tar -czvf file name.tar.gz file name.SQL unzip it : tar -zxvf file name.tar.gz back up all data base : mysqldump -uroot --all-databases | gzip > mysql_username.sql
tail : like cat, but only reads the end of the fileCode:1. Login to your server as root via SSH. 2. Type: cd /scripts 3. Type: ./pkgacct username (replace username with the acount username you wish to backup) 4. You will not see something along the lines of this: Copying Reseller Config...Done Copying Mail files....Done Copying proftpd file....Done Copying www logs...Done Grabbing mysql dbs...Done Grabbing mysql privs...Done Copying mailman lists....Done Copying mailman archives....Done Copying homedir....Done 5. There will be a file now in /home called cpmove-username.tar.gz where username is the username specified in step #4. 6. Download the cpmove-username.tar.gz and save it. (You can use your FTP software to login to the server and download the file) How To restore a cpmove-username.tar.gz 1. Upload cpmove-username.tar.gz to the webserver's /home directory. (You can use your FTP software to login to the server and upload the file) 2. Type: /scripts/restorepkg username username.tar.gz (replace username with the account username) This will restore the site, and also create the cPanel account.
tail /var/log/messages : see the last 20 (by default) lines of /var/log/messages
tail -f /var/log/messages : watch the file continuously, while it's being updated
tail -200 /var/log/messages : print the last 200 lines of the file to the screen
more : like cat, but opens the file one screen at a time rather than all at once
more /etc/userdomains : browse through the userdomains file. hit to go to the next page, to quit
pico : friendly, easy to use file editor
pico /home/burst/public_html/index.html : edit the index page for the user's website.
vi : another editor, tons of features, harder to use at first than pico
vi /home/burst/public_html/index.html : edit the index page for the user's website.
grep : looks for patterns in files
grep root /etc/passwd : shows all matches of root in /etc/passwd
grep -v root /etc/passwd : shows all lines that do not match root
touch : create an empty file
touch /home/burst/public_html/404.html : create an empty file called 404.html in the directory /home/burst/public_html/
ln : create's "links" between files and directories
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf : Now you can edit /etc/httpd.conf rather than the original. changes will affect the orginal, however you can delete the link and it will not delete the original.
rm : delete a file
rm filename.txt : deletes filename.txt, will more than likely ask if you really want to delete it
rm -f filename.txt : deletes filename.txt, will not ask for confirmation before deleting.
rm -rf tmp/ : recursively deletes the directory tmp, and all files in it, including subdirectories. BE VERY CAREFULL WITH THIS COMMAND!!!
last : shows who logged in and when
last -20 : shows only the last 20 logins
last -20 -a : shows last 20 logins, with the hostname in the last field
w : shows who is currently logged in and where they are logged in from.
netstat : shows all current network connections.
netstat -an : shows all connections to the server, the source and destination ips and ports.
netstat -rn : shows routing table for all ips bound to the server.
netstat -an | grep :80 | awk '{print $5}' | cut -f1 -d":" | sort | uniq -c | sort -n
netstat -anl | grep :80 | wc -l
ps aux | grep httpd | wc -l
top : shows live system processes in a nice table, memory information, uptime and other useful info. This is excellent for managing your system processes, resources and ensure everything is working fine and your server isn't bogged down.
top then type Shift + M to sort by memory usage or Shift + P to sort by CPU usage
ps: ps is short for process status, which is similar to the top command. It's used to show currently running processes and their PID.
A process ID is a unique number that identifies a process, with that you can kill or terminate a running program on your server (see kill command).
ps U username : shows processes for a certain user
ps aux : shows all system processes
ps aux --forest : shows all system processes like the above but organizes in a hierarchy that's very useful!
file : attempts to guess what type of file a file is by looking at it's content.
file * : prints out a list of all files/directories in a directory
du : shows disk usage.
du -sh : shows a summary, in human-readble form, of total disk space used in the current directory, including subdirectories.
du -sh * : same thing, but for each file and directory. helpful when finding large files taking up space.
wc : word count
wc -l filename.txt : tells how many lines are in filename.txt
cp : copy a file
cp filename filename.backup : copies filename to filename.backup
cp -a /home/burst/new_design/* /home/burst/public_html/ : copies all files, retaining permissions form one directory to another.
if you want to know size for file or directory
du -h /home/username/public_html/test
kill: terminate a system process
kill -9 PID EG: kill -9 431
kill PID EG: kill 10550
Use top or ps ux to get system PIDs (Process IDs)
EG:
PID TTY TIME COMMAND
10550 pts/3 0:01 /bin/csh
10574 pts/4 0:02 /bin/csh
10590 pts/4 0:09 APP
Each line represents one process, with a process being loosely defined as a running instance of a program. The column headed PID (process ID) shows the assigned process numbers of the processes. The heading COMMAND shows the location of the executed process.
Putting commands together
Often you will find you need to use different commands on the same line. Here are some examples. Note that the | character is called a pipe, it takes date from one program and pipes it to another.
> means create a new file, overwriting any content already there.
>> means tp append data to a file, creating a newone if it doesn not already exist.
< send input from a file back into a command.
grep User /usr/local/apache/conf/httpd.conf |more
This will dump all lines that match User from the httpd.conf, then print the results to your screen one page at a time.
last -a > /root/lastlogins.tmp
This will print all the current login history to a file called lastlogins.tmp in /root/
tail -10000 /var/log/exim_mainlog |grep domain.com |more
This will grab the last 10,000 lines from /var/log/exim_mainlog, find all occurances of domain.com (the period represents 'anything',
-- comment it out with a so it will be interpretted literally), then send it to your screen page by page.
netstat -an |grep :80 |wc -l
Show how many active connections there are to apache (httpd runs on port 80)
mysqladmin processlist |wc -l
Show how many current open connections there are to mysql
tmp security
/scripts/securetmp
Big size file transfer
Block and unblock an ipCode:scp /home/username/public_html/backup-5.26.2005_21-46-09_trbqtr.tar.gz root@otherserverip:/path/to/location Where serverip is the IP of the server to which you are trying to copy the file to. It will then ask you a question, just type yes. After that, it will prompt for the root password of the other server, enter it and the file transfer will begin. It will take some time so please be patient.
To find the username of a domainCode:iptables -I INPUT -s xx.xx.xx.xx -j DROP where xx.xx.xx.xx is source ip then /etc/init.d/iptables save to remove you have to delete the rule by its number iptables -D INPUT # where # is the number of the rule down when you view it by "iptables -L -n --line-numbers"
Code:grep domain.com /etc/userdomains short way to go to this account cd ~username


LinkBack URL
About LinkBacks






Reply With Quote