0

How do I SCP a file from a RHEL linux box to another RHEL linux box without the password and without the username using URIs in Java using SCPClient? I know how to do a passwordless ssh, and I can SCP a file without the password, but I'm having trouble getting it to work without the username.

Here's my guess:

Source: file:///home/username/temp.txt

Destination: scp://@192.168.1.1:/home/username/

Everlight
  • 431
  • 5
  • 18

2 Answers2

0

Have you tried scp://username@192.168.1.1:/home/username/ ?

Tassos Bassoukos
  • 16,017
  • 2
  • 36
  • 40
  • I know that works. The problem is that I don't know the "username" when I want to SCP. – Everlight Apr 02 '15 at 14:41
  • Then you cannot SSH/SCP. SSH/SCP cannot determine the use by the public key alone. – Tassos Bassoukos Apr 02 '15 at 14:42
  • @Everlight Username is mandatory... SCP is over SSH... you are logging into the remote box. – SnakeDoc Apr 02 '15 at 14:42
  • There's no way to simply attempt to login as one of the listed available users? Or rather, to use the username that you are scp-ing from without telling SCPClient what the username is? like, how I can do "ssh -Y 192.168.1.1"? - which uses the current username and passwordless ssh. – Everlight Apr 02 '15 at 14:50
  • Ah, that gets you the current username - use `System.getProperty("user.name")` to get that. – Tassos Bassoukos Apr 02 '15 at 14:59
0

Based off of the SCPClient page I'm going to say that it's not possible. So, the best method is to do

SCPClient scpc = new SCPClient
scpc.setRemoteHost( "192.168.1.1" );
scpc.getValidator().setHostValidationEnabled( false );
scpc.setAuthentication( "/home/username/.ssh/id_rsa", System.getProperty("user.name"), "" );
scpc.connect();
scpc.put( "file:///home/username/temp.txt", "scp://" + System.getProperty("user.name") + "@192.168.1.1:/home/username/" );

For my purpose its safe to assume the remote username is the same as the local username.

SnakeDoc
  • 13,611
  • 17
  • 65
  • 97
Everlight
  • 431
  • 5
  • 18