[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: ssh tutorial



On Fri, 2009-06-05 at 23:39 -0700, gmspro wrote:
> Would anyone tell how to use ssh command in brief?

Let me try my hand at a basic primer...

(1) SSH is used to login to a remote computer:

	ssh user computer

Or:
	ssh -l user computer

Where:

'user' is your username on the remote computer.

'computer' is the hostname of the remote computer, if it has a DNS A
record or an entry in /etc/hosts, or the IP address.

Examples:

	ssh jason argonaut

Logs in as 'jason' on the computer 'argonaut', assuming that the IP
address for 'argonaut' is listed in the /etc/hosts file. This approach
might be used on a small home network.

	ssh chris global proximity on ca

Logs in as 'chris' on the computer 'global.proximity.on.ca', where
'global.proximity.on.ca' has a correctly-configured DNS entry so it can
be resolved into an IP address. This approach is used for almost all
publicly-accessible machines.

	ssh jane 172 16 16 1

Logs in as 'jane' on the computer with the IP address 172.16.97.1. With
this approach you need to know the IP address but don't require an entry
in /etc/hosts or a DNS A record. This approach might be used when
initially setting up some machines on a network.

These commands will give you shell access on the remote machine, after
you have provided your password.

Additional information:

- You can leave the username out if it's exactly the same as the
username under which you logged in to the local machine:

	ssh global.proximity.on.ca

- You can add a command name if you want to run just one command instead
of accessing a shell. For example, to run 'who' on zenit.senecac.on.ca I
could use:

	ssh chris zenit senecac on ca who

- Adding the '-C' option (note the capital letter) turns on compression.
If you're going through a slow connection, this can improve performance.
If you're on a local connection (LAN), don't bother.

- Adding the '-X' option (again, a capital letter) turns on X11
forwarding. This lets you run a graphical command remotely and have it
display locally, assuming that the local system has an X server (e.g.,
the local computer is running Linux/BSD/Solaris/AIX/... with a GUI, or
it's running OSX or Windows and an X server has been started). For
example:

	ssh -XC chris concord3 virt-manager

...will run the virt-manager application on concord3 and display the
virt-manager graphical window on the local display. Note: in some
situations, depending on the ssh server configuration, you may need to
use '-Y' instead of '-X'. (Note that the -C option is also being used
here; its use with -X is strongly recommended).

(2) You can use the related 'scp' secure copy utility (or, alternately,
sftp) to transfer files to and from a remote system using ssh:

	scp user computer:/path/to/file name

This transfers /path/to/file from the account 'user' on the remote
system 'computer' to 'name' on the local system. Note that this is the
same syntax as the 'cp' (copy) command, except that 'user computer' is
placed in front of the source filename.

Examples:

	scp chris concord3:/etc/services c3s

The file /etc/services on concord3 (using account name 'chris') is
transferred to the file 'c3s' in the local current directory.

	scp chris concord3:~/todo.txt .

The file 'todo.txt' in the home directory of user 'chris' on 'concord3'
is transferred to the current directory ('.').

You can also transfer *to* a remote system, by putting the user computer
part in front of the destination file:

	scp todo.txt jason host3 example com:/tmp/

The file 'todo.txt' on the local system (current directory) is
transferred to the /tmp directory on the system 'host3.example.com'
using the account 'jason'.

(3) See the ssh documentation for information on how to use ssh with
public/private keys, eliminating the need to constantly retype the
password.

Hope this is useful--

--
Chris Tyler


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]