How to pass text that has special characters like "$" on ssh command line?

Solution Verified - Updated -

Issue

  • Need to run SSH command remotely:
[root@myserver ~]# echo $root_line
root:$6$2AAAWg0U/5sR$iDEJqNhi0ar23hRMogGrlTNlWdYnSQRVbTKwj2ovTQFLRNB376Dt/jTiiXOSg/RzLxhIeLR9lZMpfKOBwUsJS6GJR/:19187:7:99999:7:::

[root@myserver ~]# ssh -t my-user@remote_server  "sudo  sed  s#^root:.*#$root_line# /root/shadow2"
Enter login password:
root:AAAWg0U/5sR/jTiiXOSg/RzLxhIeLR9lZMpfKOBwUsJS6GJR/:19187:7:99999:7:::

$2 $6 $iDEJqNhi0hRMogGrlTNlWdYnSQRVbTKwj2ovTQFLRNB376Dt are missing. they are being interpreted as variables
[root@myserver ~]#

Environment

  • Red Hat Enterprise Linux

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content