Take the 2-minute tour ×

I am trying to copy a file from my desktop to my remote server using the sudo command. I am doing this from the remote machine since I know the password for this machine and I do not have a password for my local machine.

sudo scp donj@localhost:/Desktop/my.cnf user@remotemachine:/app/MySQL/my.cnf

This does not work however. I want to overwrite the my.cnf file in the MySQL directory. I tried the su command but I do not have the password to become a super user.

share|improve this question

migrated from stackoverflow.com Jun 3 '12 at 21:16

This question came from our site for professional and enthusiast programmers.

sudo does not copy anything nor connects to a remote machine. It is used to perform a command on behalf of another user (usually root) on the local computer. –  buc Jun 3 '12 at 19:37
Try with the scp command. –  obounaim Jun 3 '12 at 20:02

3 Answers 3

You can use the scp command which is dedicated to transfer file between computers in a network

You don't have to be root to copy a file from your local machine run this command:

scp /home/Desktop/my.cnf user@remotemachine:/app/MySQL/my.cnf

How ever if you need root privileges login as a root like this:

scp /home/Desktop/my.cnf root@remotemachine:/app/MySQL/my.cnf

Great link here

man scp for more information

share|improve this answer
How exactly does that work if he needs sudo on the remote end? Unless he can sudo scp on the remote side –  ThiefMaster Jun 3 '12 at 21:50
why does he need sudo? if he want to login as a root scp donj@localhost:/Desktop/my.cnf root@remotemachine:/app/MySQL/my.cnf @ThiefMaster –  obounaim Jun 4 '12 at 5:10
@cool_cs i have added an command to the answer. –  obounaim Jun 4 '12 at 5:12
He might not have direct root access o nthe remote machine. –  ThiefMaster Jun 4 '12 at 9:21
cat /Desktop/my.conf | ssh user@remotemachine sudo cat > /app/MySQL/my.cnf

You could also ssh to the remote machine and then do this:

sudo scp user@yourmachine:/Desktop/my.conf /app/MySQL/my.cnf
share|improve this answer
I get this message: sudo: sorry, you must have a tty to run sudo –  cool_cs Jun 3 '12 at 19:39
I don't why I get this message. –  cool_cs Jun 3 '12 at 19:50
@cool_cs try ssh -l instead of ssh –  Kaii Jun 3 '12 at 19:57
I guess sudo does not work. I get the message:Sorry, user -----_user is not allowed to execute '/usr/bin/scp jhjh@localhost:/Desktop/my.cnf userB@jijijij:/app/MySQL/my.cnf' as root on ....... –  cool_cs Jun 3 '12 at 22:21

First of all, can you login to remote system with ssh and do sudo cat /etc/shadow (just do not paste output here, we don't need it)? If you can you are good, if you can't you need to add your remote user to sudoers and/or wheel and try again.

Then, if you are doing something like this often consider adding another admin account to remote machine (not another root) with just enough permissions and groups to do what is necessary.

If you need just this time then either use one of other answers to connect and copy or upload to temporary file, connect with normal user account and sudo mv /home/user/uploadedfile.cnf /to/here/mysql.cnf and sudo chown root:root /to/here/mysql.cnf to give it right user:group.

share|improve this answer
How do you add remote user to soders/wheel? –  cool_cs Jun 4 '12 at 4:28
@cool_cs If you have any remote user that have admin rights use it. If you can login remotely as root, use it. If you can't do either of these then you must go and setup remote admin account locally. For any help with sudoers do man sudoers, /etc/sudoers file should contain something like this %wheel ALL=(ALL) ALL and in /etc/group add your admin users to wheel group. –  Sampo Sarrala Jun 4 '12 at 7:58

Your Answer


