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.
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
sshcommand, and determine the option to use to disable host key checking.
- Build a Script from the Required Commands
cloud_user‘s home directory.
Use Vim to create the file
lab.shin the new
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.
- 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.10as the first parameter to be assigned to
Press Ctrl + C to exit the password prompt.
- Add the New bin Directory to the PATH Variable
Append to the
cloud_user‘s home directory to add the new
binfolder to the
echo 'PATH="$HOME/bin:$PATH"' >> .bashrc
.bashrcto pick up the change.
Verify that you can run
lab.shwithout specifying the path to the script.