\documentclass[noanswers,addpoints,10pt]{exam}
\usepackage{datetime}
\usepackage[xetex,text={6.5in,9in},centering]{geometry}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage{multicol}
\usepackage{multirow}

\usepackage[x11names]{xcolor}
\usepackage{tcolorbox}
\usepackage{enumerate}
\usepackage{enumitem}

% compact itemized and then enumerated
\setlist{leftmargin=*,
  noitemsep,
  topsep=5pt,
  parsep=0pt,
  partopsep=0pt,
}

\setlist[enumerate]{leftmargin=*,
  itemsep=2pt,
  topsep=0pt,
  parsep=0pt,
  partopsep=0pt,
}

\usepackage{tikz}
\usetikzlibrary{arrows,automata,decorations.pathmorphing,backgrounds,positioning,fit}

\usepackage{fontspec}
\IfFontExistsTF{Gentium Book Basic}{
  \setmainfont{Gentium Book Plus}
}{
  \setmainfont{Times New Roman}
}
\IfFontExistsTF{Comic Code}{
  \setmonofont{Comic Code}[
  Scale = 0.85,
  ]
}{
}

\usepackage{float}
\usepackage{listings}
\lstset{
  basicstyle=\ttfamily,
  numberstyle=\footnotesize,
  language=java,
}

\usepackage{amssymb}
\newcommand{\checkpoint}{{\Large $\checkmark$} }

\usepackage{hyperref}


% classname
\newcommand\assignmentTitle{Worksheet: CLI \#1 -- Command-line
  Interaction w/VM}
\newcommand\semester{Spring 2025}
\newcommand\className{Security in Computer Science}
\newcommand\classNumber{CIS~371}
\newcommand\classFullName{\classNumber~\className}
\newcommand{\assignmentName}{CLI}
\newcommand{\assignmentNumber}{01}
\newcommand{\assignmentFullName}{h\assignmentNumber-\assignmentName}
\renewcommand{\dateseparator}{-}

\yyyymmdddate

% /classname


\pagestyle{headandfoot}
\firstpageheader{\classNumber\\\semester}{\assignmentTitle\\~}{\today\\~}
\runningheader{\assignmentTitle}{}{\today}

\newenvironment{show Example}[1]{
  \begingroup
  \renewcommand{\solutiontitle}{\noindent\textbf{Example:}\enspace}
  \printanswers
  \begin{solution}[#1]
  }{
  \end{solution}
  \endgroup
}

\definecolor{javafile}{rgb}{0.90, 0.87, 0.7}
\definecolor{inputfile}{rgb}{1.0, 0.7, 0.6}
\definecolor{configfile}{rgb}{0.75, 0.84, 0.66}
\definecolor{hostoutputlisting}{rgb}{0.84, 0.66, 0.75}
\definecolor{guestoutputlisting}{rgb}{0.66, 0.75, 0.84}

\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}
\let\endchangemargin=\endlist

\begin{document}
\pointsinrightmargin{}
\section*{Learning Outcomes}
After completing this assignment, a student should be able to
\begin{itemize}
\item \textbf{Copy} and \textbf{start} an Ubuntu virtual machine,
  \lstinline{UbuntuServer}, using \lstinline{VBoxManage}.
\item \textbf{Stop} the virtual machine two different ways.
\item \textbf{Use} \lstinline{ssh} to connect to the running virtual
  machine.
\end{itemize}

\section*{Procedure}
\begin{questions}

\question{} Read the assignment. This is \textbf{always} where you should
  start and \textbf{always} something you should do as soon as the
  assignment is available.

  The work \textbf{must} be done inside of a \emph{virtual machine}
  that is a copy of UbuntuServer (full path and copy instructions for
  the lab in \lstinline{VBoxManage.org}).

\question{} \textbf{Copy UbuntuServer and SSH in.}

  This first activity is done on a \emph{host} computer, a computer
  that will run the \lstinline{VirtualBox} program which runs other
  computers, \emph{guest} machines, virtually. You may install the
  \lstinline{UbuntuServer} virtual machine and run it on any computer
  with \lstinline{VirtualBox} installed. The commands here will assume
  the work is being done on a CS Department Lab machine.

  \begin{parts}
  \part{} \textbf{Open a terminal emulator for a command-line
      interface (CLI).}

    Go to the \textbf{Activities} in the desktop graphical
    environment. Start the \emph{Console} program. This will run the
    \lstinline{bash} shell program in your home directory on the lab
    machine.

  \part{} \textbf{Copy \texttt{UbuntuServer} VM.}

    The following commands, taken from \lstinline{VBoxManage.org},
    will copy the VM image from the class folder to one below your
    home directory, register the machine, and start and stop the
    machine. All of these commands are run on the \emph{host}
    machine:\footnote{The \texttt{\$} is the machine's prompt, not
      something you should type.}



\begin{lstlisting}[language={},backgroundcolor=\color{hostoutputlisting}]
$ mkdir -p ~/VirtualBox\ VMs/
$ cp -r /home/student/Classes/371/UbuntuServer ~/VirtualBox\ VMs/
$ VBoxManage registervm <your-home>/VirtualBox\ VMs/UbuntuServer/UbuntuServer.vbox
$ VBoxManage modifyvm UbuntuServer --bridgeadapter1 enp0s31f6
\end{lstlisting}

    When all of that works, you will have copied, registered, and
    updated the network on your virtual machine for the semester. It
    has a brand new Ubuntu Server 24.04 installation. The next two
    commands start and then stop the virtual machine.

\begin{lstlisting}[language={},backgroundcolor=\color{hostoutputlisting}]
$ VBoxManage startvm UbuntuServer --type headless
  Waiting for VM UbuntuServer to power on...
  VM UbuntuServer has been successfully started.
$ VBoxManage controlvm UbuntuServer shutdown
\end{lstlisting}

  \part{} \textbf{Log into the guest machine.}

    Power the machine back up, find out the IP address it is using.
    After the power up you may need to wait thirty seconds or so.

\begin{lstlisting}[language={},backgroundcolor=\color{hostoutputlisting}]
$ VBoxManage startvm UbuntuServer --type headless
  Waiting for VM UbuntuServer to power on...
  VM UbuntuServer has been successfully started.
$ VBoxManage guestproperty get UbuntuServer /VirtualBox/GuestInfo/Net/0/V4/IP
Value: 192.168.100.XX
\end{lstlisting}

    The actual IP address will be a quad of \emph{decimal}
    numbers. Use the \lstinline{Value} returned above for the
    following.

\begin{lstlisting}[language={},backgroundcolor=\color{hostoutputlisting}]
$ ssh csuser@192.168.100.XX
  csuser@192.168.1.36's password:
\end{lstlisting}

    The password is \lstinline{Kil0Ech0} (those are zeros). You will
    reset it in the next assignment.

    Notice that the next I/O box is a different color. That is to
    indicate that you are talking to the \emph{guest} machine. That
    will also be shown in the prompt.

\begin{lstlisting}[language={},backgroundcolor=\color{guestoutputlisting}]
csuser@UbuntuServer:~$ ls -lA
  total 44
  -rw------- 1 csuser csuser   52 Jan 10 18:18 .bash_history
  -rw-r--r-- 1 csuser csuser  220 Mar 31  2024 .bash_logout
  -rw-r--r-- 1 csuser csuser 3771 Mar 31  2024 .bashrc
  drwx------ 2 csuser csuser 4096 Jan 10 17:10 .cache
  -rw------- 1 csuser csuser   32 Jan 10 18:19 .lesshst
  -rw-r--r-- 1 csuser csuser  807 Mar 31  2024 .profile
  drwxrwxr-x 2 csuser csuser 4096 Jan 10 18:36 src
  drwx------ 2 csuser csuser 4096 Jan 10 17:09 .ssh
  -rw-r--r-- 1 csuser csuser    0 Jan 10 17:21 .sudo_as_admin_successful
  -rw------- 1 csuser csuser   59 Jan 10 18:19 .Xauthority
\end{lstlisting}

    That was a long directory (\lstinline{-l}) listing of almost all
    (\lstinline{-A}) of the files in the home directory.

    Now you will check the \emph{version} of \lstinline{g++} (the GNU
    C++ compiler) installed in the machine. Take note of the version
    as emailing the answer to Dr. Ladd is how you complete this
    assignment.
\begin{lstlisting}[language={},backgroundcolor=\color{guestoutputlisting}]
csuser@UbuntuServer:~$ g++ --version
  ... some output ...
\end{lstlisting}

    Finally, you will shut down the machine from \textbf{inside} using
    the \lstinline{shutdown} command. But only the superuser can run
    that command. \lstinline{csuser} can do superuser things inside
    the VM!

\begin{lstlisting}[language={},backgroundcolor=\color{guestoutputlisting}]
csuser@UbuntuServer:~$ sudo shutdown now
  [sudo] password for csuser:

  Broadcast message from root@NubuntuServer on pts/1 (Fri 2025-01-10 19:22:18 UTC):

  The system will power off now!
\end{lstlisting}

    And you are kicked back to the prompt on the \emph{host} machine.

  \end{parts}
\question{} When you are done, e-mail Dr. Ladd,
  \href{mailto:laddbc@potsdam.edu}{laddbc@potsdam.edu} with the name
  and number of the course in the \emph{subject} and the
  \textbf{version} number of \lstinline{g++} inside the virtual
  machine.

\end{questions}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
