These three lines of code require authentication twice. I don't yet have password-less authentication set up on this server. In fact, these lines of code are to copy my public key to the server and concatenate it with the existing file.
How can I re-write this process with a single ssh
command that requires authentication only once?
scp ~/local.txt user@server.com:~/remote.txt
ssh -l user user@server.com
cat ~/remote.txt >> ~/otherRemote.txt
I've looked into the following possibilities:
- command
sed
- operator
||
- operator
&&
- shared session: Can I use an existing SSH connection and execute SCP over that tunnel without re-authenticating?
I also considered placing local.txt
at an openly accessible location, for example, with a public dropbox link. Then if cat
could accept this as an input, the scp
line wouldn't be necessary. But this would also require an additional step and wouldn't work in cases where local.txt
cannot be made public.
Other references:
https://superuser.com/questions/400714/how-to-remotely-write-to-a-file-using-ssh