Bash脚本在复制到终端时有效,但在执行时不起作用

时间:2018-09-16 15:32:14

标签: bash

因此,我尝试制作一个小的bash脚本以将无密码的ssh设置到用户定义的服务器中,并且当我将其逐行复制到终端时它可以工作,但是当我尝试执行时会出现很多错误.sh文件。

#!/bin/bash
read -p "Please input the server number: " var_n
read -p "Please input username of server $var_n: " var_user
read -p "Please input IP of server $var_n: " var_ip
read -p "Please input password of server $var_n: " var_pass
read -p "Please input alias of server $var_n: " var_alias
ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ""
touch ~/.ssh/known_hosts
touch ~/.ssh/config
echo "## Server $var_n ##\nHost $var_alias\n HostName $var_ip\n User $var_user" >> ~/.ssh/config
chmod 600 ~/.ssh/config
ssh-keygen -R $var_user
ssh-keygen -R $var_ip
ssh-keygen -R $var_user,$var_ip
ssh-keyscan -H $var_user,$var_ip >> ~/.ssh/known_hosts
ssh-keyscan -H $var_ip >> ~/.ssh/known_hosts
ssh-keyscan -H $var_user >> ~/.ssh/known_hosts
sshpass -p "$var_pass" ssh $var_user@$var_ip 'mkdir -p .ssh'
cat ~/.ssh/id_rsa.pub | sshpass -p "$var_pass" ssh $var_user@$var_ip 'cat >> .ssh/authorized_keys'
var_n=""
var_user=""
var_ip=""
var_pass=""
var_alias=""

据我所知,这全部归结为两个我不知道的错误:

$ ./ssh-setup.sh
': not a valid identifieread: `var_n
': not a valid identifieread: `var_user
': not a valid identifieread: `var_ip
': not a valid identifieread: `var_pass
': not a valid identifieread: `var_alias
Generating public/private rsa key pair.
Saving key "/home/ethan/.ssh/id_rsa" failed: passphrase is too short (minimum five characters)

0 个答案:

没有答案