Linux Hands-On Lab -> Using SSH, Redirection, and Permissions in Linux

Linux Hands-On Lab -> Using SSH, Redirection, and Permissions in Linux

Linux Learning Path for Cloud and DevOps Engineers

📝Introduction

This post explains how we go over I/O redirection, file permissions, and using the ssh tool. These are skills that will serve you well in your career as a Linux SysAdmin, Cloud Engineer or DevOps Engineer.

📝Log in to the AWS Management Console

Using your credentials, make sure you're using the right Region. In my case, I am using AWS as my cloud provider and chose us-east-1. However, you are free to choose any cloud provider and create your 2 Linux Server VMs (I am using a CentOS 7 distro) for this hands-on lab.

Note: You must create the AWS Access Key and AWS Secret Access Key and configure the AWS CLI in the terminal to use it.

You can use link1 and link2 for it.

📝Enable SSH to Connect Without a Password

  1. Let's generate an SSH key:

     [<user>@<server1>]$ ssh-keygen
    

  2. Press Enter three times to accept the defaults.

  3. Then copy it over to the other server:

     [<user>@<server1>]$ ssh-copy-id <server2_IP>
    

  4. Now if we try to log into server2 without a password, it should work. Try it:

     [<user>@<server1>]$ ssh <server2_IP>
    

  5. Log out to get back to server1.

📝Copy All tar Files from one server to another

  1. Copy the files:

     [<user>@<server1>]$ scp *.gz <server2_IP>:~/
    

  2. Connect to server2 again:

     [<user>@<server1>]$ ssh <server2_IP>
    
  3. Make sure they're there:

     [<user>@<server2>]$ ll
    

    It should show the two files.

📝Extract the Files, Making Sure the Output is Redirected

  1. Extract any compressed file that you have created (I have created these files as test files):

     [<user>@<server2>]$ tar -xvf deploy_content.tar.gz >> tar-output.log
    
     [<user>@<server2>]$ tar -xvf deploy_script.tar.gz >> tar-output.log
    
  2. Take a look at what's in the directory now:

     [<user>@<server2>]$ ll
    

    We'll see the new files and their permissions.

📝Set the Umask to have New Files as Only Readable and Writeable by the Owner

  1. We need to make new files with 0600 (-rw-------) permissions. Since the default is 0666, and we want it to be 0600, run the following:

     [<user>@<server2>]$ umask 0066
    

Verify the /home/dev/deploy.sh Script Is Executable and Run It (I have created this empty script as a test file)

  1. Check permissions on deploy.sh:

     [<user>@<server2>]$ ls -l deploy.sh
    
  2. Make the script executable:

     [<user>@<server2>]$ chmod +x deploy.sh
    
  3. Run it:

     [<user>@<server2>]$ ./deploy.sh
    

Make sure it works. Your script is executable now. It's marked in green.

Congratulations — you have completed this simple hands-on lab covering the basics of I/O redirection, file permissions, and using the ssh tool.

Thank you for reading. I hope you were able to understand and learn something helpful from my blog.

Please follow me on CloudDevOpsToLearn and LinkedIn franciscojblsouza