我尝试建立远程连接的主机系统正在 SunOS 上运行。系统上没有 ssh-copy-id 可用。经过搜索,我发现以下命令在执行时会模仿 ssh-copy-id 功能。
cat ~/.ssh/id_rsa.pub | ssh remotehost 'cat >>~/.ssh/authorized_keys && echo "Host Key Copied"'
我正在尝试使用 expect 编写一个脚本来执行此操作,但它失败并出现以下错误。 代码:
#!/usr/bin/expect -f
#!/bin/bash
set username [lindex $argv 0]
set password [lindex $argv 1]
set host [lindex $argv 2]
cat ~/.ssh/id_rsa.pub | ssh remotehost 'cat >>~/.ssh/authorized_keys && echo \"Host Key Copied\"'
expect "Password:"
send "$password\n"
expect eof
错误:
invalid command name "cat"
while executing
"cat ~/.ssh/id_rsa.pub | ssh remotehost 'cat >>~/.ssh/authorized_keys && echo \"Host Key Copied\"'"
(file "./remote.sh" line 8)
通过搜索,我了解到默认情况下 expect 不会接受 shell 命令。有人可以帮助解决我的问题。提前致谢。