28 Online Photo Editing Websites To have Fun With SSH Commands ( Part II )
Apr 28

SSH Commands ( Part I )

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
NetworksAdd comments | 2,455 views | Email This Post | Stumble it!

What’s The Deal?

SSH Commands started off as a dump for linux commands by the author, having a bad memory and sometimes went through long periods of time without having to work in servers so the information was pushed out. The commands used in SSH normally don’t allow for much error so its good to have them on reference some where. From there SSH Commands was born.

Our aim now is to be a place beginners can turn to when they need help with basic SSH Commands, or that little reminder free of charge.

What is SSH?

SSH is secure shell, a tool used to connect and talk to linux servers. These commands aren’t SSH commands as such, but more so commands that can be used in SSH whilst talking to the linux server.

Most of these commands presented are based around a Red Hat/CentOS operating systems. We don’t warrant the accuracy or compatibility of the information provided here, instead provide information as a possible channel for new users, resolution seekers and more research.

Guides

Below are the SSH guides we have on site at the moment. If you have a suggestion please let us know and we’ll try and add it.

SSH Client – Connecting to SSH

Like most connects, you need a client and a server. The server will be the SSH daemon on the server, already installed on most occasions. However for someone stepping into the task, they generally just need the SSH client.

The most popular SSH client for connecting to a linux server is PuTTY. You can download this small, portable program for free at from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Getting General Command Help From Within SSH

With you are connected in with SSH, in most cases you can find help on a command by typing:

<command> –help

eg. cd –help

If that doesn’t work, you can also try:

man <command>

eg. man iptables

Man stands for manual, like a help manual.

Shell Text Editor (nano)

The best Linux text editor for SSH is nano (also known as pico but was renamed). You can create, edit and manipulate files of all types as long as they are text based in this program. It is small and easy to use and install.

nano

eg. nano httpd.conf

Browsing Directories and Paths Commands in SSH

Command: cd

Stands for change directory

It is slightly different to ms-dos but still similar. You must remember that / is the top of your disk. You can use this relatively or not.

eg. cd home

This command would only work if you were already at the top of the disk (in /). If you weren’t it would fail. If your current path is /var/log and you wanted to browse the the home directory, you would use:

eg. cd /home

Adding the / at the front of the path makes it relative to the top of the disk.

./ refers to the current directory. You may require to use it in certain commands to show the current directory

../ refers to the directory above the current directory.

For example, if the current directory path is /home/user4/public_html/downloads/programs/

./ would refer to the programs folder

../ would refer to the downloads folder

../../ would refer to the public_html folder

../../../ would refer to the user4 folder

and so on.

Listing Directory Content

To list the files and folders inside a directory you can use the ls command.

eg. ls

For better display, you can use:

eg. ls -l

On some servers, if its setup you can simply type two L’s and it will work like ls -l

eg. ll

For more advanced directory listing options type:

eg: ls –help

If you would like to run a filter over the results you can add a pipe, followed by the grep command and then your criteria..

eg. ll | grep index

OR

eg. ll | grep .php

Don’t forget if ll doesn’t work, use the ls or ls -al commands. Wildcards are not needed. The grep command searches for pattens in things. This is merly one example of its uses.

Making Files and Directories

There are lots of ways to create a file on the fly.

Best way is to use a text editor like nano:

nano filename.conf

OR to put something quickly in a file use:

echo “my content” > test.txt

This will create an empty file. Touch updates when a file was last updated but in this case will also create it if it doesn’t exist:

touch test.txt

Make a directory, you can use:

mkdir <dir name>

Deleting

Command: rm

Delete the folder and everything under it:

rm -r <dir>

To delete everything without prompting for delete add a -f in there too:

rm -rf <dir>

Delete a file:

rm <filename>

Delete file without prompt:

rm -f <filename>

So to delete everything under the “downloads” directory you could:

Example 1:

cd /home/user1/public_html/
rm -rf download

This would delete the download directory, without prompt and everything under it.

Example 2:

cd /home/user1/public_html/download
rm -rf ./*

Mounting

If you have a second HDD (hard disk drive) installed, such as for back up purposes you can mount it at /backup.

mount

eg. mount /dev/hdc2 /backups

* Note: Need to create /backups (as in the directory) before you mount it.

Check Binded IP addresses

ifconfig

Under eth0 you’ll see something like:

inet addr:xx.79.162.45 Bcast:xx.79.162.45 Mask:255.255.255.248

Gives you the IP details. The “lo” one is the loopback adapter, allows it to talk to itself. Insane hey?

Useful symbols including wildcards

One powerful feature is the use of the < and > symbols. They allow you to write information to and from a file.

eg. echo “my data” > test.conf

The above command will replace all the file content with “my data”. If you want add to the bottom of the file:

eg. echo “my data” >> test.conf

It also works the other way too. For example if you have an sql back up in backup.sql, you can import it:

eg. mysqldump -B [database name] -u [username] -p < backup.sql

The * symbol refers to everything. For example to delete everything in the current folder use:

rm -rf ./*

What is fsck?

Stands for “File system check” – It checks the disk for corrupt sectors and attempts to repair. Can be used when errors like “seg fault” appear and other situations.

File System Permissions

Permissions in the file system are broken down into:

  • File permissions
  • Group permissions

Permissions can be assigned to files and directories.

File permissions can be adjusted with the CHMOD tool (stands for change mode). Permissions are broken up to Read, Write, Execute. These permissions can then be assigned to root (master user), the group, and everyone (general public like web guests).

Permissions are represented by a number (CHMOD Numbers).

Digit rwx Result
0 no access
1 –x execute
2 -w- write
3 -wx write and execute
4 r– read
5 r-x read and execute
6 rw- read and write
7 rwx read write execute

Remembering that permissions are assigned to three groups (root, group and everyone) each group is assigned a number. For example, 777 refers to full access for everyone. Numbers 775 or 755 are the general permissions assigned to web directories and pages.

To change the CHMOD permissions:

chmod

eg. chmod 755 index.html

or for a directory:

eg. chmod 755 public_html

To mass change permissions, which you must be VERY careful of, you can use the -r parameter because it changes everything.

eg. chmod -r 755 public_html

Everything under public_html will now have the permission of 755 (root full access, group read and execute, public read and execute).

There is an excellent tutorial showing more in depth information on mode and group permissions located at http://www.library.yale.edu/~lso/workstation/docs/permissions/

Common Paths and File Locations

MYSQL Config – /etc/my.cnf
MYSQL - /usr/local/mysql/

SSH Config – /etc/ssh/ (generally the conf file with sshd in it)

Apache (or httpd) – /usr/local/apache/ OR /etc/httpd
Apache Conf file – /usr/local/apache/conf/httpd.conf
Apache Daemon – /usr/local/apache/bin/apachectl

Logs – /var/log/

User Data – /home/

Restarting Services (Apache, Mysql, etc)

If setup, you can generally use the “service” command. eg:

service httpd restart

It’s a shortcut method to accessing daemons.

HTTPD – service httpd restart OR service apache restart
MYSQL – service mysql restart

Running Scripts/Programs

You can do so in two ways:

Change directory to the correct path then execute:

cd /scripts
./scriptname

OR

/scripts/scriptname

For sh scripts, you need to put sh in front of it:

cd /scripts
sh scriptname

OR

sh /scripts/scriptname

Repairing Databases

pathtomysql/bin/mysqlcheck -B –repair

Generally the path to mysql is /usr/local/mysql/ but not always.

If you get an access denied error, you need to login first. If you have root access you can just add a -p on the end.

pathtomysql/bin/mysqlcheck -B -p –repair

Do not enter your password in the command. It will prompt you to login after you press enter. If you need to login with a user account (not root) add an -u for user.

pathtomysql/bin/mysqlcheck -B -u -p –repair

The -B parameter means select a single database or two or three. If you want to repair all of them, use -A instead (root required):

pathtomysql/bin/mysqlcheck -A -p –repair

Remember the different ways of accessing the program:

a) cd pathtomysql/bin/
./mysqlcheck -A -p –repair

b) /pathtomysql/bin/mysqlcheck -A -p –repair

c) mysqlcheck -A -p –repair

Sometimes servers are setup (sbin) so you don’t have to type all the full paths or change to them.

Source: http://www.sshcmds.com/

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Leave a Reply

Security Code: