![stdin과 함께 ssh-copy-id를 사용하는 방법은 무엇입니까?](https://linux55.com/image/182061/stdin%EA%B3%BC%20%ED%95%A8%EA%BB%98%20ssh-copy-id%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
다른 유사한 질문이 있다는 것을 이미 알고 있지만 답변이 도움이 되지 않았습니다. 다른 포럼에서는 SSH 키를 사용하거나 사전 설치하라는 제안이 있지만 내 시스템에서는 SSH 키를 사용하거나 사전 설치할 sshpass
수 없습니다 .sshpass
stdin in 또는 다른 방법을 사용하여 ssh-copy-id
SSH 키를 원격 서버에 복사하고 싶습니다. .stdin을 사용하여 stdin을 통해 비밀번호를 전달할 수 있습니다 echo
.
이 같은:
echo -e "1234" | ssh [email protected] "echo "my_key" >> ~/.ssh/authorized_keys"
이것은 CentOS 시스템에 있습니다.
답변1
SSH_ASKPASS
이를 위해 이 변수를 사용할 수 있습니다.
connect.sh
#!/bin/bash
pwd="mypassword"
if [ ! -t 1 ]; then
# The output is not going to stdout, assume the invoke is from SSH_ASKPASS
printf "%s\n" "$pwd"
exit 0
fi
# SSH_ASKPASS will be used only if DISPLAY is defined
export DISPLAY=:0
# Set the SSH_ASKPASS program to THIS script+
export SSH_ASKPASS="$0"
# setsid is required (Run a program in a new session)
setsid ssh-copy-id user@localhost