Exhibit 5.1

Graphic

126 East King Street
Lancaster, PA 17602

Tel (717) 299-5201 Fax (717) 291-4660

www.barley.com

Paul G. Mattaini, Esquire

Direct Dial Number: (717) 399-1519

E-mail: pmattaini@barley.com

July 21, 2026

Juniata Valley Financial Corp.
Bridge and Main Streets
P.O. Box 66
Mifflintown, PA 17059

Re:Form S-8 Registration Statement

Dear Ladies and Gentlemen:

We have acted as counsel to Juniata Valley Financial Corp. (“Juniata”) in connection with the registration under the Securities Act of 1933, as amended, by means of a registration statement on Form S-8 (the “Registration Statement”), of 300,000 shares of the $1.00 par value common stock of Juniata (“Common Stock”), to be issued pursuant to the 2026 Long Term Incentive Plan of Juniata Valley Financial Corp. (the “Plan”). The Registration Statement also registers an indeterminate number of additional shares which may be necessary to adjust the number of shares registered thereby for issuance as the result of a stock split, stock dividend or similar adjustment of the outstanding Common Stock.

This opinion letter is provided pursuant to the requirements of Item 601(b)(5)(i) of Regulation S-K of the Securities and Exchange Commission for inclusion as an exhibit to the Registration Statement.

The law covered by the opinions expressed herein is limited to the federal law of the United States of America and the law of the Commonwealth of Pennsylvania. Our opinions herein are subject to the following conditions and assumptions:

(1)   The shares of Common Stock issuable pursuant to the Plan will continue to be validly authorized on the dates the Common Stock is issued pursuant to the terms of the Plan;

(2)   The shares of Common Stock will be sold and issued strictly as described in the Plan and in accordance with the statutory laws of the United States of America and the Commonwealth of Pennsylvania.

(3)   No other change occurs in applicable law or the pertinent facts; and


July 21, 2026

Page 2

(4)   The provision of “blue sky” and other securities laws as may be applicable have been complied with to the extent required.

Based upon and subject to the foregoing, and subject to the assumptions set forth herein, we are of the opinion that the shares of Common Stock to be issued pursuant to the Plan have been duly authorized and, upon receipt by Juniata of the consideration required thereby, will be legally issued, fully paid and nonassessable.

We consent to the filing of this opinion as Exhibit 5.1 to the Registration Statement and to the reference to this firm under the caption “Legal Opinion” in the prospectus which is part of the Registration Statement. In giving this consent, we do not thereby admit that we are within the category of persons whose consent is required under Section 7 of the Act, the rules and regulations of the Commission promulgated thereunder, or Item 509 of Regulation S-K.

Very truly yours,

Barley Snyder LLP

By:

/s/ Paul G. Mattaini

Paul G. Mattaini, Esquire