1
PubkeyContent=$(cat $Pubkey)    
read -r -d '' SSH_SCRIPT <<EOM
    \$(grep ${PubkeyContent} ~/.ssh/authorized_keys")
EOM

I got the wrong result.

[Debug] SSH_SCRIPT = $(grep ssh-rsa AAAAB3NzaC1yc2EAAAzSb7WKnMsysGA8kuq5Ysp02Y75d5 sam ~/.ssh/authorized_keys")com

I want this result

 [Debug] SSH_SCRIPT = $(grep "ssh-rsa AAAAB3NzaC1yc2EAAAzSb7WKnMsysGA8kuq5Ysp02Y75d5 sam@com" ~/.ssh/authorized_keys")

1 Answer 1

1

A simple fix would be to quote the PubkeyContent variable content inside the here-doc, i.e.

read -r -d '' SSH_SCRIPT <<EOM
    \$(grep "${PubkeyContent}" ~/.ssh/authorized_keys")
EOM

or if you are using bash/ksh/zsh shell it supports a way to automatically slurp in the file content using input re-direction < file and thereby avoiding the useless use of cat. You can apply that inside command substitution as

read -r -d '' SSH_SCRIPT <<EOM
    \$(grep "$(<"$Pubkey")" ~/.ssh/authorized_keys")
EOM
Sign up to request clarification or add additional context in comments.

3 Comments

What do you mean? What are you getting instead?
I think i kew why it is not working .... because the public key is created by windows...
@Samuel: You can fix the DOS endings from the key and try the logic above again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.