If $f\otimes_\mathbb{Z}\mathbb{Z}/(p)\colon M\otimes_{\mathbb{Z}}\mathbb{Z}/(p)\to N\otimes_\mathbb{Z} \mathbb{Z}/(p)$ is onto for all $p$, $f$ onto? This lemma is used in a theorem I'm reading, with no proof.

Suppose $f\colon M\to N$ is a morphism of free, finitely generated $\mathbb{Z}$-modules. Then if $f\otimes_\mathbb{Z}\mathbb{Z}/(p)$ is surjective for all primes $p$, then $f$ is surjective itself. 

The text says it is clear. Why is the lemma true?
 A: Since $N$ is finitely generated, we have an exact sequence
$$M\stackrel{f}{\rightarrow} N\rightarrow \mathbb{Z}^k\times T\rightarrow 1$$
where $T$ is finite and $k \ge 0$. If $f$ is not surjective then either $k\ge 1$ or $T$ is nontrivial.
Since tensoring is right-exact, tensoring this sequence with $\mathbb{Z}/p$ gives:
$$M/pM\stackrel{f\otimes\mathbb{Z}/p}{\longrightarrow} N/pN\longrightarrow (\mathbb{Z}/p)^k\times T/pT\longrightarrow 1$$
If $k\ge 1$ (ie, $f(M)$ has infinite index in $N$), then and since $(\mathbb{Z}/p)$ is nontrivial for any $p$, we find that $f\otimes\mathbb{Z}/p$ is not surjective for any $p$.
If $T$ is nontrivial, then for any $p\mid |T|$, we find that $pT\subsetneq T$, so $T/pT$ is nontrivial. Thus, $f\otimes\mathbb{Z}/p$ is not surjective for any $p\mid |T|$.
In either case there exist primes $p$ for which $f\otimes\mathbb{Z}/p$ is not surjective.
EDIT: At first I tried proving this via elementary means - ie, given preimages of $n\in N$ mod every prime, I tried to stitch them together to get a preimage of $n$ over $\mathbb{Z}$. While this must be possible, I couldn't divine a formula quickly. I guess the lesson here is - when dealing with modules (or in general working in any abelian category), exact sequences are your friend.
A: 
Let $R$ be a commutative unitary ring, $M$ an $R$-module, $N$ a finitely generated $R$-module, and $f:M\to N$ a homomorphism. Suppose that $\bar f:M/\mathfrak mM\to N/\mathfrak mN$ is surjective for every maximal ideal $\mathfrak m$ of $R$. Then $f$ is surjective.

$f$ surjective $\Leftrightarrow$ $f_{\mathfrak m}:M_{\mathfrak m}\to N_{\mathfrak m}$ surjective for every maximal ideal $\mathfrak m$ of $R$.
$\bar f$ surjective $\Leftrightarrow$ $\operatorname{Im}\bar f=N/\mathfrak mN$ $\Leftrightarrow$ $\operatorname{Im}f+\mathfrak mN=N$ $\Rightarrow$ $\operatorname{Im}f_{\mathfrak m}+\mathfrak mN_{\mathfrak m}=N_{\mathfrak m}$. 
Since $N_{\mathfrak m}$ is finitely generated, by Nakayama lemma we get $\operatorname{Im}f_{\mathfrak m}=N_{\mathfrak m}$, that is, $f_{\mathfrak m}$ is surjective.
