Tutorials Hut

Tutorials Hut

  • Unix For Testers

       Introduction to Unix
       Unix System Architecture
       Unix File System Structure
       Absolute and Relative Path
       Basic Unix Commands
       cal command in Unix
       who command in Unix
       date command in Unix
       clear command in Unix
       more command in Unix
       whoami command in Unix
       uname command in Unix
       man command in Unix
       echo command in Unix
       Unix File System Commands
       ls command in Unix
       cat command in Unix
       cp command in Unix
       mv command in Unix
       pwd command in Unix
       cd command in Unix
       mkdir command in Unix
       rmdir command in Unix
       rm command in Unix
       touch command in Unix
       dirname command in Unix
       tar command in Unix
       Unix Links(ln)
       Hard Link
       Soft Link
       Regular Expressions
        Basic Regular Expressions
       Interval Regular Expressions
       Pipes and Filters
       Unix Text Processing Commands
       cmp command in Unix
       diff command in Unix
       comm command in Unix
       cut command in Unix
       Paste command in Unix
       head command in Unix
       tail command in Unix
       wc command in Unix
       sort command in Unix
       grep command in Unix
       Process Related Command
       top command in Unix
       ps command in Unix
       nice command in Unix
       Kill command in Unix
       nohup command in Unix
       time command in Unix
       File Tranfer Commands in Unix
       file transfer using scp command
       file transfer using rlogin command
       file transfer using telnet command
       ssh(Secure Shell) command in Unix
       ftp file transfer command
       sftp file transfer command
       chmod command in Unix
       File Permission and File Security in Unix



  • File Transfer in Unix using scp, ssh, ftp, sftp commands

    File transfer in Unix is possible from local system to remote server or vice versa using various commands like scp, ftp, sftp, rlogin etc. Some tools are winscp, filezilla etc. 

    We will cover below topic in this article:

    scp file transfer command in Unix

    In Unix, SCP (the scp command)  securely copy files and directories between remote hosts without starting an FTP session or logging into the remote systems explicitly. The scp command uses SSH to transfer data, so it requires a password or passphrase for authentication or can use FTP , simplest file transfer protocol to exchange files to and from a remote computer or network.

    SCP in Unix allows you to securely copy files and directories between two locations:

        • From local system to a remote system.
        • Remote system to your local system.
        • Between two remote systems from your local system.
    Transfer file using SCP
      •  When transferring data with scp, both the files and password are encrypted so that anyone intruding doesn’t get any sensitive information.
    SYNTAX:
    scp [OPTION] sourcefile1 destfile2

    options are scp options like ssh port, recursive copy etc.
    Local files should be specified using an absolute or relative path, while remote file names should include a user and host specification.

    Points to remember:
    1. scp command depends on ssh for data transfer, ssh key or password to authenticate on the remote systems.
    2. colon (:) is used to distinguish between local and remote locations.
    3. Read permissions on the source file and write access on the target system is required to copy file.

    Copy Files using scp command in Unix

      1. Copy a file from local system to remote system
        To copy file from local systen to remote system,below command can be used:

        scp localfile1.txt [email protected]:/remote/myDataDir

        here remote_username is the user of the remote server and /remote/myDataDir is the location on the remote server where file will be copied.

      2. Copy a file from remote system to local system
        To copy a file from remote system to your local system, below command can be used:

        scp [email protected]:/remote/myDataDir/remotefile1.txt local/myFiles
      3. To copy files from one remote server to other remote server, below command can be used:
        scp [email protected]:/remote/myDataDir/remotefile1.txt [email protected]:/remote/Directory

        rlogin command in Unix

      • rlogin establishes a remote connection from your terminal to a remote machine. 
      • allows an authorized user to login to other UNIX machines on a network and to interact
      • A secure version of rlogin (slogin) was combined with two other UNIX utilities, ssh and scp, created to replace the earlier utilities.
      • rlogin is considered useful for simple logins that don’t require a lot of control over the client/host interaction
    SYNTAX:
    rlogin [options ] username hostname

    **Security Issues in rlogin:The main problem with rlogin was that it sent user passwords over a network without any encryption.
    This meant that any attacker with access to the network could read user names and passwords. 

    telnet command in Unix

    Telnet is an old network protocol that is used to connect to remote systems over a TCP/IP network.
    It connects to servers and network equipment over port 23
     
      • Both data transfer including user-id and password is unencrypted 
      • Known vulnerabilities with telnet
      • Telnet is used where a lot of customization is desired, for multiple sessions

    ssh(Secure Shell) command in Unix

    Both rlogin and telnet are not secure connections with many vulnerabilities helping malicious users/hackers to get access to login details and session content.

    ssh stands for “Secure Shell”.
    It is used to securely connect to a remote server/system. SSH transfers data in encrypted form between host and client.
    ssh(secure shell connection) is :

      • secure
      • encrypted form of remote connection 
      • preferred over most other methods

    Prerequisites:

    • SSH client of your choice
    • SSH server on the remote machine
    • The IP address or name of the remote server
     
    SYNTAX:
    ssh hostname

    hostname is IP address or name of remote server.

    Default user is current login user on client machine:

    ssh [email protected] (or)
    ssh –l username hostname [ telnet syntax ]

    Command execution through ssh:

    ssh [email protected] "ls"

    Every ssh login/command execution requests for user password

    Generate SSH Keys Using SSH Keygen

      • Generate a key pair with the keygen utility to improve security of SSH connections.
      • The pair consists of a public and private key.
      • The public key can be shared, while the private key needs to stay secure.
      • SSH key pairs are used to authenticate clients to servers automatically.
      • When you create an SSH key pair, entering password to access a server is not required.

    Create a key pair on host machine

    ssh-keygen -t rsa

    To use default settings, hit Enter on the prompts for file location and passphrase.

    Copy Public SSH Key

    Copy the public key to a server. The key is the file id_rsa.pub previously created with SSH keygen command above.

    Run the command below from the client, to copy your key generated to the server:

    ssh-copy-id hostname_or_IP

    Enter the password to authenticate when asked.
    After this, you will no longer need to use the password to connect to the same server.

    Copy a File Remotely over SSH with SCP

    You can securely copy files over the SSH protocol using the SCP tool. The basic syntax is:

    scp fileName [email protected]:/home/username/destination

    To know more on SCP refer here.

    ftp command in Unix

    FTP (File Transfer Protocol) is a standard network protocol used to transfer files to and from a remote network.

      • Transfer files to and from a remote machine.
      • Allows the user to work with files on a remote machine.

    Note: FTP traffic is not encrypted. You can use SCP or SFTP or secure transfer.

    Prerequisites:

      1. Read permission on source file.
      2. Write permissions on target/remote system.
    SYNTAX: 
    ftp [hostname]

    here hostname is the remote server IP address or domain name.

    Few commands that are used when doing file transfer using FTP command:

    • help – list all available FTP commands.
    • cd – change directory on the remote machine.
    • lcd – change directory on the local machine.
    • ls – list the names of the files and directories in the current remote directory.
    • mkdir – create a new directory within the current remote directory.
    • delete – remove a file in the current remote directory.
    • rmdir- remove a directory in the current remote directory.
    • get – copy one file from the remote to the local machine.
    • mget – copy multiple files from the remote to the local machine.
    • put – copy one file from the local to the remote machine.
    • mput – copy one file from the local to the remote machine.

            put command in Unix

    put command is used to transfer file from the source terminal to the destination terminal.

    • you can use this command to upload the file.
    SYNTAX:
    put filename

    get command in Unix

    get command is used to transfer a file from destination terminal to source terminal. 

    • Use get command to download single file from the remote server.
    • File is downloaded to the directory from which ftp command is typed.
    SYNTAX: 
    get filename
    • multiple files can be downloaded using mget command.
    SYNTAX: 
    mget file1 file2 file3

           sftp (Secure File Transfer) command in Unix

    SFTP (SSH File Transfer Protocol) is a secure file protocol that is used to access, manage, and transfer files over an encrypted SSH transport.

      • It is more secure and easier to configure as compared to FTP.
      • Supports most of the interactive commands
      • SFTP allows you to perform operations on remote files.
      • SFTP works on a client-server model

    Note: If you are working on a desktop, you can use SFTP client like WinSCP or FileZilla to connect to the remote server, download or upload files.

    SYNTAX:
    sftp [email protected]_Server_OR_hostName

    Specified file is copied:

    sftp [[[email protected]]host[:file [file]]]

    Connect to particular directory:

    sftp [[[email protected]]host[:dir[/]]]

     

    Recommended Articles:

     


















  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    Scroll to Top