0
votes

My goal is to copy a folder from a remote server to a new local machine via script. I run the script from deploystudio so this is all done in root.So the script is suppose to

1) create .ssh and authorized_keys folder on the local machine

2) Paste the remoteserver's id_dsa.pub into the local authorized_keys file

3) Secure copy Folder1 from the remote server to local machine's Desktop

The Folder1 fails to copy over. If I sudo the SCP line and manually run it, it would work after I enter the password.

user="name"
id_dsa.pub="ssh-dss AAAAB3NzaC1kc3MAAACBAPpK/k7Yk............"

mkdir /Users/${user}/.ssh
chmod 0700 /Users/${user}/.ssh
touch /Users/${user}/.ssh/authorized_keys
chmod 0644 /Users/${user}/.ssh/authorized_keys

/bin/cat > "/Users/${user}/.ssh/authorized_keys" << EOL
${id_dsa.pub} 
EOL

scp -r [email protected]:/Users/admin/Desktop/Folder1 /Users/$user/Desktop
1
Why do you need to fill authorized_keys with sudo? You’re running as root anyway. Are you sure the username on the server at 192.168.1.39 is supposed to be remoteserver?Christopher Creutzig
oops, i copied the wrong line.. I was using sudo for testing in terminal. i updated the code. its suppose to be /bin/cat > "/......../" << EOLuser3225946
well, remoteserver is just an alias because i didnt want to give out real information. I am able to successfully scp when im in terminal, but it just fails in this script. I cant figure out why.user3225946
You shouldn't have a space around the equal sign, try variable="some string" And always quote your strings and variablesReinstate Monica Please

1 Answers

1
votes

Creating that file on the local system does not help you connect to the remote system. For that you want to use ssh-copy-id