**General question**: Given a vector bundle $E \rightarrow M$ on a complex manifold $M$, and a connection $\nabla$ on $E$, is it possible to find an Hermitian structure on $E$ such that $\nabla$ is the associated metric connection (i.e. the unique connection compatible with both the metric and the complex structure)?


**Specific question**: Given a line bundle $L \rightarrow X$ on a compact Riemann surface $X$ equipped with a flat connection $\nabla$, is it possible to find an Hermitian structure on $L$ such that $\nabla$ is the associated metric connection? 


**Motivation**: I´m trying to prove that a degree zero line bundle on a compact Riemann surface always admits an harmonic Hermitian metric. By a classical result of Weil and Atiyah every degree zero vector bundle admits a flat connection, moreover I think (though I still did not prove it) that the flatness condition on the connection could be translated (by computation on the vector fields $\partial z$ and $\partial \overline{z}$) into the harmonicity condition on the "associated" (in the sense of the question) Hermitian metric.


The question is clearly related to the well discussed question: [When can a Connection Induce a Riemannian Metric for which it is the Levi-Civita Connection](https://mathoverflow.net/questions/54434/when-can-a-connection-induce-a-riemannian-metric-for-which-it-is-the-levi-civita). But I´m not able to adjust the proof given in the mentioned question to an answer for my own. I´m asking also a general version of the question because I´m just curious about the answer.


Thank you for your time!


**Edit**: As pointed out by David Speyer the metric connection is constructed taking as input an Hermitian structure on the bundle and not an Hermitian metric on the manifold. I changed both the questions consequently.



Metric associated to a Connection on a Vector Bundle
alvarezpaiva's answer shows that the answer to your question is no in general.


I will answer your motivation question instead, for which the answer is positive.


If $L$ is a holomorphic line bundle over a compact Kähler manifold $(M^n,\omega)$
with $\omega$-degree zero, then there is a Hermitian metric on the fibers of $L$ with curvature $F$ and $\omega$-trace of the curvature equal to zero (what you call a harmonic Hermitian metric)


$$\omega^{n-1}\wedge F=0.$$


This is just the Hermitian-Yang-Mills equation, and I am saying that it can always be solved in the case of line bundles.


This follows from simple Hodge theory. Start with any Hermitian metric on $L$, and call $F$ its curvature $(1,1)$-form. Since $L$ has $\omega$-degree zero, you have that
$$\int\_M \omega^{n-1}\wedge F=\int\_M \Lambda F \omega^n=0.$$
Now solve the Poisson equation 
$$\Delta h=\Lambda F,$$
which can be done because of the integral of the RHS being zero.
It follows that the new Hermitian metric on $L$ that you obtain by conformally rescaling the one you have by $e^h$, has curvature
$$F\_h=F-i\partial\overline{\partial}h$$
and by construction
$$\omega^{n-1}\wedge F\_h=0,$$
which is what you want.


