\documentclass{article}
\usepackage{amsmath}
\usepackage[mathlines]{lineno} %% <- remove [mathlines] to omit equation line numbers
\usepackage{etoolbox} %% <- for \pretocmd, \apptocmd and \patchcmd
%% Patch 'normal' math environments:
\newcommand*\linenomathpatch[1]{%
  \cspreto{#1}{\linenomath}%
  \cspreto{#1*}{\linenomath}%
  \csappto{end#1}{\endlinenomath}%
  \csappto{end#1*}{\endlinenomath}%
}
%% Patch AMS math environments:
\newcommand*\linenomathpatchAMS[1]{%
  \cspreto{#1}{\linenomathAMS}%
  \cspreto{#1*}{\linenomathAMS}%
  \csappto{end#1}{\endlinenomath}%
  \csappto{end#1*}{\endlinenomath}%
}

%% Definition of \linenomathAMS depends on whether the mathlines option is provided
\expandafter\ifx\linenomath\linenomathWithnumbers
  \let\linenomathAMS\linenomathWithnumbers
  %% The following line gets rid of an extra line numbers at the bottom:
  \patchcmd\linenomathAMS{\advance\postdisplaypenalty\linenopenalty}{}{}{}
\else
  \let\linenomathAMS\linenomathNonumbers
\fi

\linenomathpatch{equation}
\linenomathpatchAMS{gather}
\linenomathpatchAMS{multline}
\linenomathpatchAMS{align}
\linenomathpatchAMS{alignat}
\linenomathpatchAMS{flalign}


\begin{document}

\section{Numerando Linhas Matemáticas}

\subsection{Exemplo 5}

\linenumbers
\begin{align*}
|MA_{k}|^2&=(x-x_{k})^2+(y-y_{k})^2\\
(x-x_{k})^2+(y-y_{k})^2&=(x^2-2\cdot x_{k}\cdot x+x_{k}^2)+(y^2-2\cdot y_{k}\cdot y+y_{k}^2)\\
(x-x_{k})^2+(y-y_{k})^2&=x^2+x_{k}^2+(-2\cdot x_{k}\cdot x)+y^2+y_{k}^2+(-2\cdot y_{k}\cdot y)
\end{align*}
\nolinenumbers

\subsection{Exemplo 6}

\linenumbers
\begin{align*}
& |MA_{k}|^2=(x-x_{k})^2+(y-y_{k})^2\\
& (x-x_{k})^2+(y-y_{k})^2=(x^2-2\cdot x_{k}\cdot x+x_{k}^2)+(y^2-2\cdot y_{k}\cdot y+y_{k}^2)\\
& (x-x_{k})^2+(y-y_{k})^2=x^2+x_{k}^2+(-2\cdot x_{k}\cdot x)+y^2+y_{k}^2+(-2\cdot y_{k}\cdot y)
\end{align*}
\nolinenumbers


\end{document}
