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
Let's generate an SSH key:
[<user>@<server1>]$ ssh-keygen
Press Enter three times to accept the defaults.
Then copy it over to the other server:
[<user>@<server1>]$ ssh-copy-id <server2_IP>
Now if we try to log into
server2
without a password, it should work. Try it:[<user>@<server1>]$ ssh <server2_IP>
Log out to get back to
server1
.
📝Copy All tar
Files from one server to another
Copy the files:
[<user>@<server1>]$ scp *.gz <server2_IP>:~/
Connect to
server2
again:[<user>@<server1>]$ ssh <server2_IP>
Make sure they're there:
[<user>@<server2>]$ ll
It should show the two files.
📝Extract the Files, Making Sure the Output is Redirected
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
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
We need to make new files with
0600
(-rw-------
) permissions. Since the default is0666
, and we want it to be0600
, 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)
Check permissions on
deploy.sh
:[<user>@<server2>]$ ls -l deploy.sh
Make the script executable:
[<user>@<server2>]$ chmod +x deploy.sh
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