louxiu
louxiu

Reputation: 2915

how to escape quote in ssh command

I want to install a the pub key for user test using the command below.

I know the root password and the user test does not exist.

cat test.pub | ssh [email protected] "useradd -m test || su - test -c 'umask 077; mkdir /home/test/.ssh; cat >> /home/test/.ssh/authorized_keys'"

But the command does not work.

Error: Creating mailbox file: File exists

Upvotes: 0

Views: 268

Answers (1)

louxiu
louxiu

Reputation: 2915

The problem is useradd -m test. I delete user test by userdel test && rm -rf /home/test. It should be userdel -r test.

The command below works:

cat test.pub | ssh [email protected] "useradd -m test && su - test -c 'umask 077; mkdir /home/test/.ssh; cat >> /home/test/.ssh/authorized_keys'"

Upvotes: 1

Related Questions