In this hands-on lab, we’re going to write a shell script for connecting to Linux Academy Linux servers from another Linux (or Mac) host, without having to first accept the RSA fingerprint.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Determine What Options Should Be Used with the ssh Command
View the man page for the
ssh
command, and determine the option to use to disable host key checking.- Build a Script from the Required Commands
Create a
bin
folder incloud_user
‘s home directory.mkdir bin
Use Vim to create the file
lab.sh
in the newbin
folder.vim bin/lab.sh
Create the following script.
#!/bin/bash login_user=cloud_user if [ -n $1 ] then ssh -o StrictHostKeyChecking=no $login_user@$1 fi
Then, save the file by running.
:wq
- Execute and Verify the Script
Save the file, and make it executable.
chmod u+x bin/lab.sh
Run the script, passing
10.0.1.10
as the first parameter to be assigned to$1
../bin/lab.sh 10.0.1.10
Press Ctrl + C to exit the password prompt.
- Add the New bin Directory to the PATH Variable
Append to the
.bashrc
file incloud_user
‘s home directory to add the newbin
folder to thePATH
environment variable.echo 'PATH="$HOME/bin:$PATH"' >> .bashrc
Source
.bashrc
to pick up the change.. .bashrc
Verify that you can run
lab.sh
without specifying the path to the script.lab.sh 10.0.1.10