Lesson 5

Dates: 6/6/2018
Linux networking
Linux System Administration

Practical Exercises with network services
  • Start virtual machine kvm2
    virsh start kvm2
  • Figure out the IP address of kvm2: check out the content of file
    /var/lib/libvirt/dnsmasq/virbr0.status specifically the line containing kvm2. It has both the MAC address and the IP address of kvm2:
    cat /var/lib/libvirt/dnsmasq/virbr0.status

    Place the IP address and kvm2 host name into file /etc/hosts on your desktop. For example, if IP address of kvm2 is
    echo '  kvm2' >> /etc/hosts
    ssh to kvm2 as user hostadm:
    ssh hostadm@kvm2

  • Install telnet server on the VM.
    sudo -s
    apt-get install telnetd
    Check /etc/inetd.conf and make sure you see the following entry:
    telnet  stream  tcp   nowait  telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd
    Command netstat -na should show open tcp/23 port:
    tcp    0   0*           LISTEN
    Telnet to kvm2 from your desktop machine, for example:
    telnet kvm2

  • Install FTP server on the VM.
    apt-get install ftpd
    Check out /etc/inetd.conf and notice the entry for FTP:
    ftp  stream  tcp     nowait  root    /usr/sbin/tcpd  /usr/sbin/in.ftpd
    Command netstat -na shows open tcp/21 port:
    tcp     0    0*     LISTEN
    From the desktop, ftp to kvm2.
    ftp  kvm2
    Use hostadm user credentials (login name and password).

  • Configure SSH.
    For SSH authentication, you can use either RSA or DSA public/private keys besides password. We'll be using RSA in the exercises below.
    To generate an RSA key pair, type the following command at a shell prompt on your desktop:
    ssh-keygen -t rsa
    Accept the default file location of ~/.ssh/id_rsa. Enter a passphrase different from your account password and confirm it by entering it again.
    The public key is written to ~/.ssh/id_rsa.pub. The private key is written to ~/.ssh/id_rsa.
    Never distribute your private key to anyone.
    The contents of ~/.ssh/id_rsa.pub needs to be delivered onto the remote machine to which you want to connect, specifically kvm2, into file ~/.ssh/authorized_keys
    To accomplish the transfer task, here you can use ftp service installed in the previous exercise.
    ftp  kvm2
    Name (kvm2:hostadm): hostadm
    ftp> cd .ssh
    ftp> lcd .ssh
    ftp> put id_rsa.pub authorized_keys
    ftp>  quit
    Command cd in the ftp> shell above is for stepping into the directory, .ssh, on the remote host, kvm2.
    Command lcd is for stepping into the directory, .ssh, on the local desktop.

    Now try to ssh to kvm2. You should be prompted to enter your passphrase.

    The ssh-agent can be used to store your passphrase so that you do not have to enter it each time you make a ssh or scp connection.
    At a shell prompt on the desktop, type the following command:
    exec /usr/bin/ssh-agent $SHELL
    Then type the command:
    and enter your passphrase(s). If you have more than one key pair configured, you will be prompted for each one. When you log out, your passphrase(s) will be forgotten. You must execute these two commands each time you log in to a virtual console or open a terminal window.

  • Run a remote command over ssh, for example:
    ssh kvm2 "uname -a"
    Copy files from your desktop to kvm2 and vise versa using scp command:
    scp kvm2:/etc/hosts .
    touch somef.txt
    scp somef.txt kvm2:/home/$USER

  • Syncronizing directories between remote hosts by using rsync.
    This tool lets you copy files and directories between a local host and a remote host.
    Install rsync on both your desktop and kvm2:
    apt-get install rsync
    Creat a directory tree and copy it over to kvm2 with rsync command.
    mkdir -p dir1/dir2/dir3
    rsync  -avz dir1 kvm2:/home/$USER
    Option a stands for archive (preserve links and timestamps); v is for verbose and z is for data compression when sending-receiving.

  • Disable telnet, and ftp
    Since you have fully functioning SSH on kvm2, you can get rid of telnet and ftp servers. In file /etc/inetd.conf comment-out the lines for telnet and ftp. Make inetd daemon to re-read the modified /etc/inetd.conf by executing the following command:
    kill -HUP inetd_PID
    where the process ID, inetd_PID, for inetd can be found from
    ps -ef | grep inetd
    Alternatively, you can simply run
    pkill -HUP inetd
    Make sure ports tcp/21, tcp/23 are not open by running
    netstat -na
    Never run rsh, rlogin, telnet and ftp servers on the open Internet. They are very unsecure due to clear text authentication and data transfer.

  • Take me to the Course Website