사용자 생성 및 ssh 액세스 구성을 자동화하려고했습니다. 이것은 그 후, 잘 작동bash 스크립트를 통해 호스트에 SSH 키를 추가하는 방법
expect -c '
spawn ssh '$user'@'$ip';
expect "assword: ";
send "'$passwd'\r";
expect "prompt\n";
send "adduser '$new_user'\r";
...
send "mkdir /home/'$new_user'/.ssh\r";
expect "prompt\n";
send "exit\r";
'
나는 허가에에는 .pub 키 파일을 추가 할 필요가 다음과 같이
지금까지 나는 호스트에 액세스하는 스크립트를 생성하고 기대를 통해 새로운 사용자를 만듭니다 키 파일을 호스트에, 지옥이 시작되었습니다.
ssh_key='/home/.../key.pub'
content=$(cat $ssh_key)
expect -c '
spawn ssh '$user'@'$ip' "echo '$content' >> /home/'$new_user'/.ssh/authorized_keys;
expect "password:";
...
'
을 얻은 :
내가 노력
missing "
while executing
"spawn ssh [email protected] ""
couldn't read file "<ssh .pub key content> ...
가 나는 또한 시도 : 난 단지 암호 쿼리가 깜박 얻을, 성공없이
cat $ssh_key | ssh [email protected]$ip "cat >> /home/$new_user/.ssh/authorized_keys"
그럴 수 없어 기대를이 마지막 방법과 연결하십시오.
http://shellcheck.net/을 사용하는 습관을 들일 수 있습니다. 버그가 발생했을 수 있습니다. –