As you pointed out, if $g$ is a primitive root of $n \ge 3$, then the primitive roots must be among $g, g^2, \dots, g^{\varphi(n)-1}$.
To count the exact number, as you observed, we need to show that for $1 \le k \le\varphi(n)-1$, $g^k$ is a primitive root iff $k$ is relatively prime to $\varphi(n)$.
Suppose that $k$ is relatively prime to $\varphi(n)$. Then there exist integers $x$ and $y$ such that $xk=y\varphi(n)+1$. It follows that $(g^k)^x=(g^{\varphi(n)})^y g\equiv g\pmod{n}$. Since $g^{kx}\equiv g\pmod{n}$, for any $e$ we have
$$g^e\equiv (g^{kx})^e\equiv (g^k)^{xe}\pmod{n}.$$
It follows that any power of $g$ is congruent to some power of $g^k$. This implies that $g^k$ is a primitive root of $n$.
On the other hand, if $k$ is not relatively prime to $\varphi(n)$, let $d \gt 1$ be a common divisor. Then $(g^k)^{\varphi(n)/d}\equiv 1\pmod{n}$, since $k\varphi(n)/d$ is a multiple of $\varphi(n)$. It follows that $g^k$ has order $\le \varphi(n)/d$, so cannot be a primitive root.