Changes

Jump to: navigation, search

SSH

6,318 bytes added, 00:07, 10 January 2011
no edit summary
[[Category:SBR600]][[Category:Linux]]
SSH is the Secure Shell tool, a powerful encrypted communication tool.This page contains some basic information about the use of SSH. = Using SSH for a Text-Based Connection = The most basic use of SSH is for a text-based connection used to enter commands and view command output, or execute a text-based application such a menu-driven system. The basic form of the ''ssh'' client command is:  ssh [''OPTIONS''] [''user''@]''host'' ''command'' Note that the ssh command name may vary, depending on the software used. Where:* ''user'' is the name of the user account on the remote computer (optional, if the user account name is the same on both systems)* ''host'' is the name or IP address of the remote computer* ''command'' is the command to be executed on the remote computer (optional - the default is to open whatever shell or application is the default for the specified user)  Useful options include:{|border="1" cellspacing="0" cellpadding="2" width="100%"!Option||Description||Example|-| -C||Enable compression (gzip) to enhance performance||ssh -C ''user''@''host''|-| -X or -Y||Turn on X11 forwarding (it is recommended that -C also be used) - See X11 Tunnelling, below||ssh -X -C ''user''@''host''|-| -L or -R||Turns on tunnelling||(See Tunnelling section)|-| -i ''identityfile''||Specifies the private key file to be used (default: all private keys in ~/.ssh)||ssh -i ~/.ssh/id_dsa ''user''@''host''|} == Examples ==* Connect to a shell for account 'kim' on the computer 'winter': <code>ssh kim@winter</code>* Like above, with compression: <code>ssh kim@winter</code>* Run <code>df -h</code> on the remote system, and display the graphics on the local computer: <code>ssh -XC kim@winter firefox</code>  = Using SSH for a Graphical Application (X11 Tunnelling) = SSH is capable of carrying graphical traffic using the X Window System (X11) protocol. This means that if your client system is running the X Window System (most Unix/Linux systems, and any Mac or Windows system on which an X Server has been started), you can run remote graphical programs and display the output (windows) locally. To enable this, add the <code>-X</code> or <code>-Y</code> options to your command line. The difference between -X and -Y is that (ideally) the -X option will prevent certain advanced types of access which are not required by most graphical programs and which may present a security vulnerability, such as taking a screenshot of your desktop. == Example ==* Run Firefox on the remote system, and display the graphics on the local computer: <code>ssh -XC kim@winter firefox</code>  = Using SSH with Tunnelling = In addition to X11 tunnelling, SSH permits you to set up your own tunnels to carry arbitrary network traffic either from the client system to the server, or from the server to your client. This allows you to encrypt the traffic for security/privacy, and to circumvent firewalls. For local, forward (client to server) tunnels, the syntax is:  ssh -L ''listenport'':''destinationhost'':''destinationport'' [''OPTIONS''] [''user''@]''host'' [''command''] Where:* ''listenport'' is the port on the client machine which will accept connections* ''destinationhost'' is the remote computer hostname or IP address to which connections will be directed. This is usually <code>localhost</code>, which denotes the SSH server, but it can also be the name of a system which the server can directly reach. Note that communication between the server and the ''destinationhost'' is '''not''' encrypted.* ''destinationport'' is the port on the ''destinationhost'' to which the connection will be directed For reverse (server to client) tunnels, the syntax is:  ssh -R ''listenport'':''destinationhost'':''destinationport'' [''OPTIONS''] [''user''@]''host'' [''command''] The arguments have the same meaning, but are executed one the opposite hosts, so the tunnel listens on the server and communicates to the destination through the client system. == Examples == * To connect port 8080 on the local computer to port 80 on the server ''winter'', using the account ''sam'': <code>ssh -L 8080:localhost:80 sam@winter</code>** After the tunnel above was put in place, you could access <code>http://localhost:8080/</code> and be connected to the webserver (port 80) on the host ''winter''* To connect port 2000 on the local computer to port 1234 on the host ''spring'', which is on the same LAN as the SSH server ''winter'': <code>ssh -R 2000:spring:1234 sam@winter</code>* To connect port 3000 on the server ''winter'' to port 5900 on the local computer: <code>ssh -L 3000:localhost:5900 sam@winter</code>  = Using SSH for File Transfer = SSH provides two mechanisms for file transfer: ''scp'' and ''sftp''. == scp - Secure Copy == The ''scp'' command functions like the normal Unix/Linux copy (cp) command, but accepts a hostname (and optional user ID) prepended to a filename for copying to/from remote systems:  scp [''user''@]''host'':''sourcefilename'' [''user''@]''host'':''destinationfilename'' === Examples === * Copy the file <code>/etc/hosts</code> from this computer to the <code>/tmp</code> directory on the computer ''ireland'': <code>scp /etc/hosts ireland:/tmp</code>* Copy the file <code>test.tar</code> from the home directory of the user ''chris'' on the computer ''ireland'' to the current directory: <code>scp chris@ireland:~/test.tar .</code> == sftp - Secure FTP == ''sftp'' provides an encrypted version of FTP. The command usage is:  sftp [''user''@]''host'' At which point you can use any standard FTP command. === Example === * Open a secure FTP connection to the account ''john.doe'' on the server ''matrix.senecac.on.ca'': <code>sftp john.doe@matrix.senecac.on.ca</code> == Graphical File Management over SSH == Many Linux graphical file managers, such as the GNOME ''Nautilus'' and KDE ''Konqueror'' programs, know how to manage files remotely using the ssh/scp/sftp protocols. For example, on GNOME, you can select the menu option Places>Connect to Server, enter the connection details, and view a file management window on a remote server. You can then rename, copy, move, and delete files using drag-and-drop operations (for example, you can copy a file by dragging it from your desktop to the remote window). You can also create bookmarks for rapid access to remote filesystems at a later date. 
= Using SSH with Public-Key Authentication =

Navigation menu