Every set of $n$ generators is a basis for $A^{n}$

For a (let's say commutative) ring $R$, a left $R$-module is Hopfian if every surjective $R$-module map from $M$ to $M$ is an isomorphism. The exercise in Atiyah-Macdonald can thus be restated as: every finitely generated free module over a commutative ring is Hopfian.

In fact a stronger result is true: every finitely generated module over a commutative ring is Hopfian. The proof is a quick -- but somewhat tricky -- application of Nakayama's Lemma. See for instance $\S 3.8.2$ of my commutative algebra notes. The argument given there is taken from (page 9!) of Matsumura's Commutative Ring Theory. (The proof does not require homological algebra although a few of the exercises in Atiyah-Macdonald do.)

Note that an easy example of a non-Hopfian module is the direct sum of countably many copies of any nonzero $R$-module $M$, so finite generation is an absolutely necessary hypothesis.

Let me address a couple of questions you ask later in your post.

1: $A^n$ is not a local ring when $n > 1$ (and $A \neq 0$, of course). Your description of the maximal ideals makes reference to the $i$th component, so by varying $i$ you get more than one maximal ideal.

2: No, if $\mathfrak{m}$ is a nonzero maximal ideal of $R$, then $k = R/\mathfrak{m}$ need not be a flat $R$-module. For instance, when $R$ is a domain, every flat $R$-module is torsionfree hence faithful, but $k$ has a nonzero annihilator $\mathfrak{m}$. However it is still true that after tensoring with $k$ the sequence is exact, for instance by an argument involving $\operatorname{Tor}$ as noted in the comments, or as Matt notes, since the freeness of the last term in the original short exact sequence means the sequence splits, and tensoring a split exact sequence results in another split exact sequence.


At the OP's request, I am converting some of my comments above into an answer:

Firstly, $A^n$ is never being considered as a ring, just an $A$-module, so it doesn't make sense to say that $A^n$ is local. (Locality is a property of rings, not modules.) As a side point, if $n>1$ and $A$ is non-zero, then $A^n$ is never local, so it is good that locality of $A^n$ is not required!

(To prove this last point: let me take $n=2$ for concreteness. If $A$ is non-zero, it contains a maximal ideal $m$. Then $A\times m$ and $m\times A$ are both maximal ideals of $A^2$, so $A^2$ cannot be local. A differently phrased, more geometric, argument is that Spec $A^2$ is the disjoint union of Spec $A$ with itself, hence is disconnected, while Spec of a local ring is always connected. The two arguments are closely related, in fact.)

Secondly, $k$ will not be flat as an $A$-module unless $A=k$ (see here), so, while it is true that one would have exactness after tensoring with $k$ were flat as an $A$-module, that flatness will almost never hold. The point is that if $0 \to M^′\to M \to M^{′′}\to 0$ is an exact sequence of $A$-modules with $M^{′′}$ flat and $N$ is any $A$-module, then $0\to M^′\otimes N \to M\otimes N\to M^{′′}\otimes N \to 0$ is again exact. There are various ways to see this: Steve D notes one (an argument with Tor) in his comment above. As Olivier Begassat notes, in your case M′′ is not just flat, but free, so in fact the original exact sequence splits, which makes it obvious that it stays exact after tensoring. (Nevertheless, the more general statement with flat modules if often very useful.)


Another remark: there are other ways to prove this (as Pete Clark notes in his answer) besides following the outline of Atiyah and Macdonald. Pete Clark has noted one (which in fact proves a more general statement).

Another is to regard $\phi$ as an $n \times n$-matrix, note that since it is a surjection it remains so after reducing modulo $\mathfrak m$ for every maximal ideal of $A$, hence is invertible modulo every $\mathfrak m$, thus has unit determinant modulo every $\mathfrak m$, thus has unit determinant, and thus is itself invertible. (Note that arguing with determinants is in some sense a way of avoiding Nakayama's lemma by using the ingredients in its proof.)