The commander of U.S. Navy destroyer USS John McCain has been relieved of his duties months after the service branch faced ridicule on social media for posting a photo of him firing a rifle with its scope mounted backward. 

Cmdr. Cameron Yaste was recently let go from his position "due to a loss of confidence in his ability to command the guided-missile destroyer," the Navy announced in a statement, without elaborating. 

Navy spokesperson Cmdr. Tim Hawkins later told Fox News Digital that the photo "had nothing to do with his recent relief from command."

In April, the Navy posted an image of Yaste aiming the rifle with a backwards scope on its Instagram account with the caption, "From engaging in practice gun shoots, conducting maintenance, testing fuel purity and participating in sea and anchor details, the #USNavy is always ready to serve and protect," according to Stars and Stripes. 

2 US AIRCRAFT CARRIER STRIKE GROUPS ORDERED TO STAY IN MIDDLE EAST WITH TENSIONS HIGH 

Cameron Yaste firing rifle

This undated photo provided by Stars and Stripes shows Cmdr. Cameron Yaste, former commanding officer of USS John McCain, fires a rifle with a scope facing backward. (Stars and Stripes via AP)

Social media users then pointed out the improper setup of the rifle. Around the same time the Navy posted the image, the Marines, on their X account, shared a similar photo of one of its members firing a rifle with the proper configuration, giving it the caption, "clear sight picture." 

The post featuring Yaste was ultimately deleted. 

"Thank you for pointing out our rifle scope error in the previous post," the Navy later wrote on social media, according to The Associated Press. "Picture has been removed until EMI (extra military instruction) is completed." 

USS John McCain is currently helping protect aircraft carrier USS Theodore Roosevelt in the Middle East. 

NAVY TO SIDELINE 17 VESSELS DUE TO MANPOWER SHORTAGE 

USS John McCain in Pacific

The guided-missile destroyer USS John McCain is seen in the Pacific Ocean in December 2003. (Petty Officer 3rd Class Todd Frantom/U.S. Navy via Getty Images)

Yaste has been temporarily replaced by Capt. Allison Christy, deputy commodore of Destroyer Squadron 21, which is part of the USS Abraham Lincoln Carrier Strike Group, currently in the Gulf of Oman along with USS John McCain. 

The Pentagon sent the carriers to the Middle East to be in position should Israel need help repelling an attack by Iran or other countries, if such a thing happens, military officials said. 

USS John McCain in Japan

USS John McCain, under repair at a dry dock, is seen after a rededication ceremony at the U.S. Naval base in Yokosuka, Japan, in July 2018. (AP/Eugene Hoshiko)

CLICK HERE TO GET THE FOX NEWS APP 

The Navy says on its website that Yaste, a native of Knoxville, Tennessee, has earned awards including the "Defense Meritorious Service Medal, Navy and Marine Corps Commendation Medal (three awards) and Navy and Marine Corps Achievement Medal (two awards)." 

The Associated Press contributed to this report.