1

I am trying to transfer a file between two network switches.

Topology:

SwitchA------SwitchB (10.219.20.209)

Below are the steps I tried:

  1. Generated the public ssh-key on SwitchA using this command -

    ssh-keygen -t rsa

  2. Copied the newly generated key from SwitchA to SwitchB using this command -

    scp /root/.ssh/id_rsa.pub root@10.219.20.209:/root/.ssh/id_rsa.pub

  3. Tried transferring the file now, however its still asking for the credentials.

    root@RE:0% scp test.sh root@10.219.20.209:/tmp/
    Password:

Please suggest how I can achieve the file transfers passwordless.

8
  • You could use netcat. Strangely my comment has been deleted by someone. – Artem S. Tashkinov Mar 3 at 18:08
  • What is it that you're trying to achieve? Do you want to copy files from SwitchA to SwitchB without entering a password? Or do you think the file copied in step 2 was not successfully copied for some other reason? – Wieland Mar 3 at 18:43
  • 2
    Try putting the contents of id_rsa.pub into /root/.ssh/authorized_keys, not /root/.ssh/id_rsa.pub. – jsbillings Mar 3 at 20:25
  • 1
    You will have to create a new file called /root/.ssh/authorized_keys. That's how PubkeyAuthentication works, the server on the remote side has the pubkey from the client side in the user's ~/.ssh/authorized_keys. – jsbillings Mar 4 at 13:25
  • 1
    @jsbillings thanks for your inputs. they are juniper networks QFX5100 platform running JUNOS. – U cLoUdz Mar 5 at 7:19
2

I believe that with Juniper switches, there is a unique syntax for configuring authentication.

Here is the syntax:

authentication {
(encrypted-password "password" | plain-text-password);
load-key-file URL filename;
no-public-keys;
ssh-dsa "public-key";
ssh-ecdsa "public-key";
ssh-rsa "public-key";
}
1
#!/usr/bin/expect --

set arg1 [lindex $argv 0]
set arg2 [lindex $argv 1]
set DATE [exec date +%Y_%m_%d-%H.%M.%S]

spawn echo $DATE
spawn ssh $arg1 -l root

expect {   
          "*(yes/no)*"  { send "yes\r" }
          "Password:"   { send "Juniper\r" }
}
expect {
         "Password:"   { send "Juniper\r" }
         "*@*" {send " \r" }
}
set FILE $arg2 
append FILE "_"
append FILE $DATE

send "cd /var/tmp/; cp $arg2 $FILE ; echo \"\" > NH-HALP.log \r"
expect  "*@*"
send "scp \"$FILE\" root@10.219.43.163:/var/tmp/\r" 
expect {
          "*(yes/no)*"  { send "yes\r" }
          "Password:"   { send "Juniper\r" }
}
expect {
         "Password:"   { send "Juniper\r" }
         "*@*" {send " \r" }
}
0

Step 2: use ssh-copy-id root@10.219.20.209

Also, verify the rights of /root/.ssh on 10.219.20.209. They must be drwx------.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.