That is $b=ua$ with $u\in\mathbb{Z}_n^*$ if and only if $(a,n)=(b,n)$. It is easy enough to prove the forward direction using the Bezout identity, and easy enough to find the requisite unit in practice by solving $ax\equiv b\pmod n$. Dividing out the $\gcd=d$, we can solve $(a/d)x\equiv b/d\pmod{n/d}$ because $a/d$ is a unit modulo $n/d$, and then select a unit modulo $n$ from the $d$ solutions $x=x_0+t\,n/d$ with $t=0,\dots,d-1$. What is hard is to prove that there is always a unit modulo $n$ among them. Not all of them are, $8\equiv2\cdot4$ modulo $12$ does not work, but $8\equiv5\cdot4$ does.
The above construction does show that if $(a,n)=(b,n)$ then $b=xa$ and $a=yb$, so $a$ and $b$ are "associates" in the terminology of Anderson et al., and generate the same ideal in $\mathbb{Z}_n$. However, the only proof I know that they are "strong associates", i.e. $b=ua$ with a unit $u$, is rather involved, see In $\mathbb{Z}/(n)$, does $(a) = (b)$ imply that $a$ and $b$ are associates? It uses the above ideal, reduction to prime powers and Chinese remainder theorem. Is there a proof that uses elementary properties of gcd and modular arithmetic? For example, a direct proof that if $(x_0,m)=1$ then $(x_0+tm,md)=1$ for some $t=0,\dots,d-1$?