Showing posts with label LX0-104 commands. Show all posts
Showing posts with label LX0-104 commands. Show all posts

Friday, December 23, 2016

Configuring OpenSSH

Configuring OpenSSH



SSH server (sshd)




/etc/ssh/sshd_config 


Directives:

- AllowUsers

- DenyUsers

- HostKey

- ListenAddress

- PermitRootLogin

- Port

- Protocol







SSH client 





/etc/ssh/ssh_config





file.







The





/etc/ ssh/ssh_config 






file is used to specify default parameters for all users running ssh on the system.





A user can override these defaults using the





~/.ssh/ssh_config 






file in his or her home directory.






The precedence for ssh client configuration settings are as follows:





1. Any command-line options included with the ssh command at the shell prompt



2. Settings in the ~/.ssh/ssh_config file



3. Settings in the /etc/ssh/ssh_config file










Connect




ssh –l user_name ip_address





Don’t forget the –l parameter. If you don’t, the SSH client will
attempt to authenticate you to the remote system using the same
credentials you used to authenticate to the local system.







Encryption III

Tunnel your X server traffic to remote X clients using an SSH

Tunnel your X server traffic to remote X clients using an SSH



To configure a remote X client without encryption, you can use the
following procedure:





1. On the remote X client, enter



   xhost +X_server_hostname



   This tells the client to accept connections from the X server.





2. On the X server, enter



   DISPLAY=X_client_hostname:0.0



   and then enter



   export DISPLAY



   This tells the X server to display its output on the remote X client.






3. From the X client, use the ssh client to access the shell prompt on
   the X server and then run the graphical application you want displayed
   on the X client. For example, you could enter gedit at the shell
   prompt to remotely display the gedit text editor. You could also enter
   office at the shell prompt to remotely display the OpenOffice.org
   suite.







Encrypted

This procedure works, but all the X traffic is transmitted
unencrypted. This isn’t good. Instead, you should use SSH to tunnel
the X server traffic between the X server and the X client. You can do
this using one of the following options:




On the X client system:



• Use the –X option with the ssh client program.




• Set the



  ForwardX11 



  option to a value of




  yes




  in the




   /etc/ssh/ssh_config 





    file








On the X server system:





Once this is done, you then need to set the




X11Forwarding 




option to





yes 





in the





/etc/ssh/sshd_config 





file






Encryption IV

SSH to tunnel POP3 traffic

SSH to tunnel POP3 traffic





Let’s walk through an example of how you can use SSH to tunnel POP3 traffic:





1. Make sure the ssh client is installed on the local system where the

   e-mail client will run.



2. Make sure the sshd daemon is installed and running on the POP3 server.



3. Ensure IP port 22 is open on the server where sshd is running.



4. On the system where sshd is running, switch to root and edit the





  /etc/ssh/sshd_config 





   file.




5. Locate the AllowTcpForwarding parameter, uncomment it if necessary,
   and then set it to a value of yes. An example is shown here:




    AllowTcpForwarding  yes




6. Save your changes to the file and exit the editor.



7. Restart the sshd daemon by entering systemctl restart sshd at the
   shell prompt (as root).




8. Switch to the client system.




9. Create a local ssh tunnel from a local high IP port (in this
   example, port 2345) to port 110 on the POP3 server using the following
   command (enter the remote user’s password when prompted):




    ssh -f -N -L 2345:pop3_host_address:110 user_name@pop3_host_address





   The options specified in this command do the following:




   • –N and –f 


      Tell ssh not to execute a command remotely on the server
      and to run in the background after prompting for the remote user’s
      password

 


   • –L

      Specifies three things:

      • The local port to be used for the client end of the tunnel (in
        this case, 2345)


      • The hostname or IP address of the remote POP3 server


      • The port on the remote server that will be used for the server
        end of the tunnel (in this case, 110)



   You don’t have to use port 2345. You can use the same port on both
   ends if desired. However, be aware that you will need to switch to the
   root user if you want to use a port number less than 1024 on the
   client side of the tunnel. These are called privileged ports.




10. With the tunnel established, configure the local e-mail client
    program to retrieve mail from the local system on the port you
    configured for the client end of the SSH tunnel. In this example, you
    would configure it to get mail from the local system’s IP address on
    port 2345. An example of how to do this with the Evolution e-mail
    client is shown in Figure 18-6.



    Note that I used the hostname of the local host, not the POP3 server, in the Server field.
    I also added the port number of the workstation end of the tunnel to the end of the
    hostname.







At this point, when the client uses the POP3 protocol to download new
messages, the SSH client on the local system will encrypt the request
and forward it to the SSH server through the SSH tunnel you
established. The SSH server will receive the request, decrypt it, and
then pass the data on to the local port 110, where the POP3 daemon is
listening. The cool thing about this process is that it is completely
transparent to the e-mail client software. As far as it’s concerned,
it’s retrieving e-mail from a local POP3 server.



You can test the tunnel you created using the telnet command from the
client end of the tunnel. The syntax is




telnet localhost client_tunnel_port



Here’s an example:





telnet localhost 2345






Encryption IV

SSH to Use Public Key Authentication


SSH to Use Public Key Authentication



1. At the shell prompt of the client system



ssh-keygen –t rsa




or



ssh-keygen –t dsa





2. When prompted for the file in which the private key will be saved,
press enter to use the default filename of



~/.ssh/id_rsa 



or



~/.ssh/id_dsa




The associated public key will be saved as




~/.ssh/id_rsa.pub 



or



~/.ssh/id_dsa.pub






The next thing you need to do is to copy the public key you just
created to the SSH server. 




scp ~/.ssh/key_name.pub   user_name@address_of_SSH_server:filename






At this point, the contents of the key file you just copied need to be
appended to the end of the 





~/.ssh/authorized_keys 




file in the home directory of the user you will connect to the SSH server as.







If desired, you can use the



ssh-agent 



command to eliminate the need to enter the passphrase every time you establish 
an SSH connection.





1. At the shell prompt of your client system, enter



ssh-agent bash


2. At the shell prompt, enter




   ssh-add ~/.ssh/id_rsa 




   or




   ssh-add ~/.ssh/id_dsa






   depending on which key file you have created.




3. When prompted, enter the key file’s passphrase. When you do, you
   should be prompted that the identity has been added. An example
   follows:



      rtracy@ws1:~> ssh-agent bash
      rtracy@ws1:~> ssh-add ~/.ssh/id_rsa
      Enter passphrase for /home/rtracy/.ssh/id_rsa:
      Identity added: /home/rtracy/.ssh/id_rsa (/home/rtracy/.ssh/id_rsa)
      rtracy@ws1:~>






    Once this is done, the ssh-agent process stores the passphrase in
    memory. It then listens for SSH requests and automatically provides
    the key passphrase for you when requested.





Encryption V



Using GPG to encrypt files : Revoke

Using GPG to encrypt files : Revoke


1) To create (not issue) the key revocation certificate, enter





gpg --output revoke.asc --gen-revoke key_ID



gpg --output revoke.asc --gen-revoke 899AB9E6









Remember, you can use the




--fingerprint option


gpg --fingerprint student@fedora






with the gpg command to view the key ID number. 







2) Issue Revocation





gpg --import revocation_certificate_filename




gpg --import revoke.asc









Encryption VI

Using GPG to encrypt files : Symmetric

Using GPG to encrypt files : Symmetric


With the public keys imported, we could exchange encrypted files and be able to decrypt them.



The syntax for doing this is





gpg --output output_filename --symmetric encrypted_filename








For example, if I sent the mytest- file.txt.gpg encrypted document
from my openSUSE system to my fedora system, I would enter the
following command to decrypt it







gpg --output mytestfile.txt.decrypted --symmetric  mytestfile.txt.gpg











Encryption VI

Using GPG to encrypt files : View Keys

Using GPG to encrypt files : View Keys



You can view the keys in your GPG keyring using the




gpg --list-keys





The keyring file itself is located in the




~/.gnupg/




directory within my home directory and is named




pubring.gpg







Encryption VI

Using GPG to encrypt files : exchange

Using GPG to encrypt files : exchange 






But what do you do if you want to be able to exchange
encrypted files with someone else and both of you be able to decrypt them?





1)  Copy your public keys to a public key server on 
the Internet.



gpg --keyserver hkp://subkeys.pgp.net --send-key key_ID 



gpg --keyserver hkp://subkeys.pgp.net --send-key 9DF54AB2 






key ID is: 

gpg --fingerprint key_owner_email 













2) You can also just directly exchange keys between systems. 




a)

gpg --export --armor key_owner_email > public_key_filename 



gpg --export rtracy@openSUSE > gpg.pub 





b)

Each user can then copy their key file to the other users. 


scp gpg.pub student@fedora: 





c)

Once this is done, each user should import the other users’ public 
keys into their GPG keyring using the 



gpg --import public_key_filename 



pg --import gpg.pub 









Encryption VI

Using GPG to encrypt files : decrypt

Using GPG to encrypt files : decrypt



gpg 




gpg --output output_filename --decrypt encrypted_filename




gpg --output mytestfile.txt.decrypted --decrypt mytestfile.txt.gpg









Encryption VI

Using GPG to encrypt files : encrypt

Using GPG to encrypt files : encrypt



gpg 




use your key pair to encrypt files and messages





gpg –e –r key_user_name filename





gpg -e -r rtracy mytestfile.txt










Encryption VI

Using GPG to encrypt files

Using GPG to encrypt files: backup


gpg 



To create a backup of your gpg key pair




gpg --export-secret-keys --armor key_owner_ email_address > filename.asc





gpg --export-secret-keys --armor rtracy@openSUSE > rtracy-privatekey.asc










Encryption VI

Using GPG to encrypt files

Using GPG to encrypt files


gpg 



1. Use GPG to generate your keys.


gpg --gen-key



At this point, your key pair has been generated! The key files are
stored in the


~/.gnupg 



he following files are created in this directory:

secring.gpg   This file is the GPG secret keyring.

pubring.gpg   This file is the GPG public keyring.

trustdb.gpg   This file is the GPG trust database.







Encryption VI