I need to do SSH to a remote server by expanding servername and user from the variables. I tried several ways but couldn't get thru the script.

  1. hardcoded servername and user which was working as expected. ssh imp_user\@servername1 Note: '@' is required

  2. Passing variables to ssh for servername and user as below $user_name ='imp_user' $server_name ='servername1' "ssh '$server_name".'@'."$server' " -- but no luck

  3. $user_name ='imp_user' $server_name ='@servername1' ssh $user_name\\$server_name -- no luck

closed as unclear what you're asking by RalfFriedl, roaima, user34720, DarkHeart, maulinglawns Mar 29 at 13:38

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    If you want an answer, you should be more specific than "no luck". Are you trying to use a shell, or a language like perl or php? It seems like a mix of those. – RalfFriedl Mar 28 at 6:17
  • If that's supposed to be shell script your syntax is way off. Look at shellcheck.net for some assistance with the basics. – roaima Mar 28 at 8:12
  • If it is shell script, you will have been given error messages (or some other output) when you tried these various attempts. What were these messages, and what did you do about it? – roaima Mar 28 at 8:13

Browse other questions tagged or ask your own question.