Accessing your Linux server’s command line, you will need to login via a SSH client.
Following are Open Source SSH Clients that are free to use:
- CopSSH
- Dropbear
- FileZilla
- KiTTY
- OpenSSH
- PuTTY (I use this)
- SunSSH
- TeraTerm
Using one of the SSH Clients to login to your servers ip for first time will ask you to verify the server's rsa2 key fingerprint, this key is important for preventing another server from impersonating your server, and stealing your username and password for your server. Once you have accepted the server's rsa2 key fingerprint, you will be asked to “login as” where you enter your username then password. In PuTTY, there is no indicator that you are typing a password. Logging in as your user will set your location on the hard drive to that of ~ (which is the user’s home directory).
Navigating your file structure via a SSH Client!
CD Change Directory
cd ~/public_html
cd least you travel between the folders of your your user’s home directory /public_html folder .
DIR Directory Listing
dir
Will lists every thing in that currently in that directory.
Changing your file structure
MV Moving command
mv this that/this
be it a file or a whole directory moving there placement is important to know by using mv –r source destination we can easily make sure that every thing that we wanted to move will get there this is handy when we come to extracting Tar, Zips, and Gz then move them to there respectable place.
Cp Copying command
cp this that/this
Copies the file or folder to another folder in the folder tree.
Useful System Information Commands
Now that we have access lets see what's the currently taking up memory and processor time in your SSH console type top
top - 15:58:12 up 15:47, 1 user, load average: 0.00, 0.01, 0.00
Tasks: 68 total, 1 running, 67 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1048576k total, 993196k used, 55380k free, 176756k buffers
Swap: 1048568k total, 20k used, 1048548k free, 482616k cached
PID | USER | PR | NI | VIRT | RES | SHR | S | %CPU | %MEM | TIME+ | COMMAND
12176 root 15 0 2428 1048 844 R 0.3 0.1 0:00.01 top
1 root 15 0 2028 888 668 S 0.0 0.1 0:00.04 init
2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
3 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0sailorstars
Now in top we can do more specific operation to see the %cpu and memory that a program takes to run.
top –u root
look in the command side for sshd and read the PID numbers
top –p ????
this will display only that operation and whatever it is currently doing.
ls –la Lists Permissions of owners and groups to folder and files
ls –la
This lets you see the current owners and groups that hold for the directory's files and folders, this your able to see who has permission and who can access what files or folder.
netstat –lnptu Who using what IP and Ports
netstat –lnptu
This list the current active connections and ip to port that are being run on your server at that current time. This is a great benefit to unlocking any network trouble for port and ip conflicts that may happen between individual applications.
Permission Setting
CHOWN Ownership command
chown user:usergroup folder
Ownership of folder and files is important to have for system security, it keeps other people from modifying the folder or files on the server.
(IE: Root can modify any file or folder but User can’t modify a folder or file owned by Root)
This being said there are time when you need to add a change in ownership or even change a user group to your folder or files under a folder. This happens when you have not set up APACHE or NGINX group layer to be apart of the folder or files owner’s group thus making the application give a access forbidden message.
CHMOD Modifying who can access
chmod 777 filename.file
Modifying a files access is one of the hardest to think about in all of the ssh commands, I say this because it give the most to either the owner or group or EVERYONE. There are time when you will need a folder to be write able but not read able or the inverse, for log files that you want to write down but not allowing Everyone to read them, or the Execution of scripts that should be executed but on written on.
There are two ways to edit a folder or files permission, Symbolic:
Reference
U for User. G for Group. O for Everyone. A for All of the above.
Operator
+ Adds permissions to the specified reference.
- Removes permissions to the specified reference.
= Sets permissions to the specified reference.
Permission
r allows reading of the folder or file.
w allows writing to the folder or file.
x allows execute to files or to allow recourse of a directory.
three others that are not important in use and are rare to use “X”, “s”, “t”.
Example
chmod ug+rw mydir
Numerical:
Permission
0 | No access
1 | Execute only
2 | Write only
3 | Write and Execute only
4 | Read only
5 | Read and Execute only
6 | Read and Write only
7 | Read and Write and Execute.
Example
chmod 755 myths.php
Other Great Tools
Wget Fast Web downloading of source files
wget http://www.example.com/
Wget allows you to download almost any files or Zipped file on the internet, this is a better and far easier then of getting files onto your server, instead of using FTP for all of your file uploads.
TAR Extracting zipped source files
tar xvfz archive_name.tar.gz
-Extract a gzipped tar archive ( *.tar.gz )
tar xvfj archive_name.tar.bz2
-Extracting a bzipped tar archive ( *.tar.bz2 )
Extracting the source files is been very handy to me for getting Magento uploaded to a web directory then using FTP to upload each folder and files every time it needs to, this is redundant and takes a lot of time for the FTP must command the Creation of a directory for the files to be housed. Take Magento, it contains numerous folders and files to run its PHP5 scripts and would normally take about 30 min to an hour to upload to check and recheck that the files exist or not.
So extracting the files and folder up at the server save you time because the operation can be done local on the hard drive instead of over the net transfers.
Just a few of the tools in the right place.