Linear algebra over a non-free f.g. module Suppose $M$ is a finitely generated module over a commutative ring $R$. I was thinking about the relation between $\operatorname{End}_R M$ and $M_n(R)$. Suppose I fix a generating set $m_1, \dotsc, m_n \in M$. 
Not all matrices $(a_{ij}) \in M_n(R)$ represent $R$ linear self-maps of $M$ via 
$$m_i \mapsto \sum_j a_{ij}m_j,$$
because some of them don't respect the relations that may hold between the $m_i$. If a relation holds on $m_i$, the same had better hold for the columns of $a_{ij}$. For example, in $\mathbb{Z}_2 \oplus \mathbb{Z}_3$, with the usual two generators, the matrix 
$$\begin{pmatrix} 0 & 1 \\ 1 & 0\end{pmatrix}$$
does not represent a map of abelian groups. So we need to look at some subalgebra $S <M_n(R)$ which does represent linear self-maps of $M$.
Further, the fact that there are relations between the generators means that in general a lot of matrices correspond to the zero transformation. So it seems we should think of $\operatorname{End}_R M$ as a quotient of $S$, by the ideal of matrices that determine the zero transformation. I see no reason why this would be a two-sided ideal in $M_n(R)$, but it will be in $S$.
So it seems that when we try to do matrix computations when working with f.g. modules, like when we prove Cayley-Hamilton and so forth, we are looking at 
$$M_n(R) \hookleftarrow S \twoheadrightarrow S/I \cong \operatorname{End}_R(M)$$
and we work so that we can do some matrix computations inside $S$ that work after we mod out by $I$. (I guess in proving Cayley Hamilton, like here, we're taking the ring to be $R[x]$.)
Can anyone offer any more clarifying perspective? I've never seen sources that discuss it like this, so any references are welcome.
 A: Saying that you have generators $m_1, \ldots, m_n$ of $M$ is equivalent to saying that there is a surjective morphism $\pi:R^n\to M$.  Let $K$ be the kernel of this morphism.  Then we have a short exact sequence
$$
0 \to K\to R^n \to M \to 0.
$$
Applying the functor $\operatorname{Hom}_R(R^n, ?)$ to this sequence, we get an exact sequence
$$
0\to \operatorname{Hom}_R(R^n,K) \to \operatorname{Hom}_R(R^n,R^n) \stackrel{p}{\to} \operatorname{Hom}_R(R^n,M) \to \operatorname{Ext}^1_R(R^n,K)=0,
$$
where the last term is zero because $R^n$ is a projective $R$-module.  Note that $\operatorname{Hom}_R(R^n,R^n) \cong M_n(R)$ as rings.
If, instead, we applied the functor $\operatorname{Hom}_R(?, M)$ to the above short exact sequence, we would get an injective morphism
$$
0\to \operatorname{Hom}_R(M,M) \to \operatorname{Hom}_R(R^n, M).
$$
If we call $Im$ the image of this morphism, then $Im$ is isomorphic to $\operatorname{End}_R(M)$ as an abelian group.  Letting $p$ be the morphism depicted in the second exact sequence above, we can define $S=p^{-1}(Im)$, which is a subgroup of $\operatorname{End}_R(R)\cong M_n(R)$.
Therefore, we have morphisms
$$
M_n(R) \hookleftarrow S \stackrel{p}{\twoheadrightarrow} S/I \cong Im \cong \operatorname{End}_R(M),
$$
where $I$ is the subgroup of $S$ of morphisms $R^n\to R^n$ in $S$ that factor through the inclusion $K\to R^n$ (this is where we can interpret the relations between the generators $m_1, \ldots, m_n$).
This allows us to explain the morphisms you are asking for in your post, with the important caveat that $S$ is a subgroup (and not a subring) and $I$ is another subgroup (and not an ideal).  (But see below).

Edit.
Thinking a bit more, we can give the following description.  $S$ will be the set of morphisms in $\operatorname{End}_R(R)$ which send $K$ into $K$, and so is a subring of $\operatorname{End}_R(R)$.  Moreover, $I$ is a two-sided ideal of $S$.
