I figured I would make an answer out the comments to the first answer addressing a point which confused me when I first learned this stuff. A morphism $f:X\to Y$ (I have to write it in this direction or else I'll confuse myself) is said to be a closed immersion if $f$ induces a homeomorphism of $X$ onto a closed subset of $Y$, and $f^\sharp:\mathscr{O}_Y\to f_*(\mathscr{O}_X)$ is surjective.
In some references I've seen it is casually remarked that the second condition is equivalent to surjectivity of the map $f_x^\sharp:\mathscr{O}_{Y,f(x)}\to\mathscr{O}_{X,x}$ for all $x\in X$. But is this really trivial? No! This map, which might reasonably be called the stalk of the morphism $f$ at $x$, is not literally the same as the stalk of $f^\sharp$ at $f(x)$. Indeed, that is a map $f_{f(x)}^\sharp:\mathscr{O}_{Y,f(x)}\to(f_*\mathscr{O}_X)_{f(x)}$. In general, there is always a natural map $\varphi_x:(f_*\mathscr{O}_X)_{f(x)}\to\mathscr{O}_{X,x}$, but it isn't in general an isomorphism. The map $f_x^\sharp$ is equal to $\varphi_x\circ f_{f(x)}^\sharp$. So while it is standard that the map $f^\sharp$ of sheaves (on $Y$!) is surjective if and only if $f_y^\sharp:\mathscr{O}_{Y,y}\to (f_*\mathscr{O}_X)_y$ is surjective for all $y\in Y$, this does not obviously say anything about surjectivity of the maps $f_x^\sharp:\mathscr{O}_{Y,f(x)}\to\mathscr{O}_{X,x}$ for $x\in X$. If however $f$ is a homeomorphism onto a closed subset $f(X)\subseteq Y$, then the stalks of $f_*\mathscr{O}_X$ at points of $Y$ are easy to compute: they are zero at points outside of $f(X)$, and at a point $f(x)\in f(X)$, we have that the natural map $(f_*\mathscr{O}_X)_{f(x)}\to\mathscr{O}_{X,x}$ is an isomorphism. So in that case, surjectivity of each $f_x^\sharp$, $x\in X$, actually will imply surjectivity of $f_y^\sharp$, $y\in Y$, and hence of $f^\sharp$.
Without the condition that $f$ is a closed topological immersion on the underlying topological spaces, it is not going to be true that $f^\sharp$ is surjective if and only if $f_x^\sharp$ is surjective for all $x\in X$. To make this clearer, let's assume $X=\mathrm{Spec}(B)$ and $Y=\mathrm{Spec}(A)$, so $f=\mathrm{Spec}(\alpha)$ for $\alpha:A\to B$ a ring homomorphism. The stalk map of $f$ at $x=\mathfrak{q}\in\mathrm{Spec}(B)$ is the ring map $A_\mathfrak{p}\to B_\mathfrak{q}$, where $\mathfrak{q}=\alpha^{-1}(\mathfrak{p})$. In general, surjectivity of this map for all $\mathfrak{q}\in\mathrm{Spec}(B)$ does not imply surjectivity of $\alpha$ itself.
I think the simplest example that will illustrate this is when $B=A_g$ is a principal localization of $A$. Then in fact the stalk map in the previous paragraph is an isomorphism for every prime ideal of $A_g$ (the set of which are in natural bijection with the set of primes of $A$ not containing $g$, i.e. $D(g)$). But the localization map $A\to A_g$ (i.e. the map on global sections of $f$) is not usually surjective. Note that in this case $f$ is a homeomorphism onto the open subset $D(g)$ of $\mathrm{Spec}(A)$, but $D(g)$ is not generally closed in $A$.
I think maybe this illustrates why the first condition is important, and why, if one wants to think about surjectivity of $f^\sharp$ in terms of the stalks of $f$, $f_x^\sharp$, for $x\in X$, the topological condition is needed, and logically "precedes" the condition on $f^\sharp$.
Lastly, I should note that the maps which I have been calling the ``stalks of $f$," $f_x^\sharp$, for $x\in X$, are in fact the stalks of the map of sheaves on $X$ (in the usual sense) $f^\flat:f^{-1}\mathscr{O}_Y\to \mathscr{O}_X$ corresponding to $f^\sharp$ under the adjunction between $f^{-1}$ and $f_*$. So surjectivity of all $f_x^\sharp$, $x\in X$, is logically equivalent to surjectivity of $f^\flat$. There is no reason to believe that $f^\flat$ is surjective if and only if $f^\sharp$ is, or even that there is an implication in either direction in general.
Best Answer
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.