2 Synthesis‎ > ‎Computing‎ > ‎Linux‎ > ‎Shell‎ > ‎

SSH & SFTP

Secure SHell provides secure remote access to another system.
  • SSH (Secure SHell) is a protocol for remotely logging into a machine. Much like Telnet, an SSH client will provide the user with a text session ("shell") on the remote machine. Unlike Telnet, SSH provides an encrypted connection between the client and the server. In practical terms, the difference between using Telnet and SSH is much like the difference between visiting ordinary websites and visiting so-called "secure" websites.
  • Similarly, SFTP (Secure FTP) is a replacement for FTP which provides an encrypted connection between the client and server for file transfer.

Server

On the server computer at the command line;
    sudo apt-get install ssh
    sudo service ssh start
The system will tell you if ssh is already installed and if it is already running.

Client

You can either login from the client computer for a Secure SHell session or
you can login for a Secure File Transfer Protocol session.

Using a Browser

To get onto an ssh server on 192.168.0.10 and log into bill's account. Type;

    sftp://192.168.0.2/home/bill/

in the URL line of a browser allows it to become a window into a remote machines filesystem.

Secure SHell session

On the client at the command line;
    ssh bill@192.168.0.10
or with the appropriate account and IP address or hostname, You get prompted for a password;
    bill@192.168.0.10's password: 
And then the servers prompt comes up;
    bill@Server:~$
"exit" is the command to close the connection. This

Secure File Transfer Protocol session

Once the SSH server is running the client can start an SFTP session with;
    sftp <hostname>
or the appropriate IP address, say;
    sftp 192.168.0.10
You will be prompted for your passphrase and then dropped into an ftp-like prompt.
    sftp>

Typing a "?" at the prompt will show you supported commands the client can use.

    supported commands that do things on the remote (server) computer:
    cd <path>    Change remote directory to 'path'
    chgrp <grp> <path>    Change group of file 'path' to 'grp'
    chmod <mode> <path>    Change permissions of file 'path' to 'mode'
    chown <own> <path>    Change owner of file 'path' to 'own'
    help    Display this help text
    ln <oldpath> <newpath>    Symlink remote file
    ls [path]    Display remote directory listing
    mkdir <path>    Create remote directory
    pwd    Display remote working directory
    rename <oldpath> <newpath>    Rename remote file
    rmdir <path>    Remove remote directory
    rm <path>    Delete remote file
    symlink <oldpath> <newpath>    Symlink remote file
   
   supported commands that do things on the local (client) computer:
    lcd <path>    Change local directory to 'path'
    lls [ls-options [path]]    Display local directory listing
    lmkdir <path>    Create local directory
    lpwd    Print local working directory
    lumask <umask>    Set local umask to 'umask'

supported commands that transfer data or do other things:
    get <remote-path> [local-path]    Download file
    put <local-path> [remote-path]    Upload file

There are a few more things to know about these commands;
If the local path is omitted on get then it will just get to the local current directory.
If the remote path is omitted on put then it will just put to the remote current directory.
Use get -r or put -r to transfer a directory and its contents. Use get -p or put -p to preserve file permissions.
   
Other supported commands:
    help    Display this help text
    exit    Quit sftp
    quit    Quit sftp
    version    Show SFTP version
    !<command>    Execute 'command' in local shell
    !    Escape to local shell
    ?    Synonym for help
   
Navigation through directories is that same as with a standard shell, ls, cd, rm, et cetera. cd will change your working directory on the remote machine and lcd will change your working directory on your local system.

The actual file transfer process is handled with the get and put commands. using the -r flag can copy a directory and all its substructure.

    get -r sourcepath [destinationpath]

The sourcepath and its entire content will be copied into the destinationpath or the current directory if none is given.


© Tom de Havas 2011. The information under this section is my own work it may be reproduced without modification but must include this notice.







Comments