Moving a file from a local computer to a server through a jump server

This is a problem I’ve been routinely facing at work because we have new firewall rules and can only access new servers through a jump box. Accessing the server through ssh isn’t a problem after I’ve ssh’d into the jump server, but moving a file from my local computer to the other server is a pain. What you need to do is move the file from your local computer to an accesible directory on the jump server. For me this involves using WinSCP to drag and drop the file to my /home/mbusche directory.

Once the file has been moved to the jump server you need to use the scp command to move the file from the jump server to the other server. In my case the command looks something like this.

scp /home/mubusche/sonar.jar mbusche@cvms1255:/home/mbusche/

The syntax is scp fileLocationOnCurrentServer username@servername:folderLocationToMoveFile/

Now generally you won’t have write access to all folders under your username and may need to sudo in as another user to move the file to the directory you need. To do that you need to login to the destination server via ssh, sign in as a user with permissions and then move the folder

ssh serverName
sudo su - userWithAccess
sudo mv /home/mbusche/sonar.jar /webdata/plugins/

Add, edit or delete sudo users using putty/bash

To add, edit or delete sudo users in putty/bash do the following

  1. Type visudo and press enter.
  2. Navigate using the arrow keys to where you want to edit.
  3. Press insert to enter edit mode.
  4. Make your changes. It is very important that you use tabs and spaces correctly.
  5. Press esc to exit edit mode.
  6. Type :wq and press enter. I remember this command as “write quit”

This is a pretty simple process, but very easy to forget when you only make changes sporadically.