We study an optimal boundary control problem for the two dimensional unsteady linearized compressible Navier–Stokes equations in a rectangle. The control acts through the Dirichlet boundary condition. We first establish the existence and uniqueness of the solution for the two-dimensional unsteady linearized compressible Navier–Stokes equations in a rectangle with inhomogeneous Dirichlet boundary data, not necessarily smooth. Then, we prove the existence and uniqueness of the optimal solution over the control set. Finally we derive an optimality system from which the optimal solution can be determined.