I want to copy my hosts to remote /etc/hosts but it doesn't work. I know root SSH access makes things easier, but IMHO root SSH access is a little dangerous. cat /etc/hosts|ssh samba2 sudo su -c sh -c cat > /etc/hostsThis command fails with permission denied; my user had sudo access.Any solutions?
I want to copy a remote txt file via SSH, but without using root access
shell;ssh;sudo;cat
cat /etc/hosts | ssh samba2 'sudo tee /etc/hosts > /dev/null'The tee is running as root, so is able to overwrite /etc/hosts with stdin.  throw away tee's stdout because we don't need/want to see it.And no need to jump through any hoops for unusual quoting.If you need to append (as in >>) instead of overwrite, you can use tee -a.