Proof Proposition 4.1 Hartshorne In this proposition, Hartshorne says and proves that any morphism of schemes between two affine schemes $f:X=\text{Spec }A  \to Y=\text{Spec }B$ is separated.
To prove this he says that the diagonal morphism $\Delta: X\to X\times_Y X$ comes from the ring morphism $A\otimes_BA\to A,\quad a\otimes a'\mapsto aa'$ which is surjective, and thus $\Delta$ is a closed immersion.
Why does the ring morphism being surjective imply $\Delta$ is a closed immersion ? It's not a general fact that the morphism induced by a surjective morphism is a closed immersion am I right ?
 A: It is exactly that, and this is proved in Exercise II.2.18 in Hartshorne.
Indeed, let $\varphi:A\to B$ be a surjective homomorphism of rings. Then $B\cong A/\ker\varphi$, so it suffices to treat the case where $B=A/I$ for an ideal $I$ and $\varphi$ is the projection. Now let $(f,f^{\#}):\operatorname{Spec}B\to\operatorname{Spec}A$ be the associated map of spectra. Note that $f$ induces a one-to-one correspondence between ideals of $B$ and ideals of $A$ containing $I$, and this correspondence preserves prime ideals as well as inclusions. In particular, $f$ is injective, and it is also not so hard to see that $f(V(J/I))=V(J)$ for any ideal $J\subseteq A$ containing $I$, so $f$ is closed. Hence $f$ is a homeomorphism onto a closed subset of $\operatorname{Spec}A$. Therefore, we are left to check that the maps $f^{\#}_{\mathfrak{p}}:\mathcal{O}_{\operatorname{Spec}A,f(\mathfrak{p})}\to\mathcal{O}_{\operatorname{Spec}B,\mathfrak{p}}$ are surjective. But these are just the natural maps $A_{\varphi^{-1}(\mathfrak{p})}\to(A/I)_{\mathfrak{p}}$, which are easily seen to be surjective.
