-1

is there a way to transfer file.txt from one of my server to another via ssh?

i have ip addresses, root usernames and passes both server's. I've read this topic ==> How to upload local file to server through Linux terminal

but i couldn't understand what hostname means? I have only ip addresses and passwords of root username. And want to transfer file.txt from server 1 to server 2 (from main folder to main folder)

Benjamin
  • 101
  • 3
  • 2
    You can indeed transfer files through SSH. What have you tried exactly? What research have you done to understand what a hostname is exactly? You can transfer a file using an ip address, instead of a hostname, by the way. – Ramhound Nov 12 '19 at 19:40
  • scp naber.sql root@xx.xx.xx.xx /tmp/ it says "cp: cannot stat 'root@xx.xx.xx.xx': No such file or directory" – – Benjamin Nov 12 '19 at 19:48
  • use a semicolon between the ip address and the path `user@ip:/dest/path` – lol Nov 12 '19 at 19:50
  • yes i'd happened. – Benjamin Nov 12 '19 at 19:53
  • it wants password in other question. I need to add this to cron, slo i have to make it in one command with adding root pass of remote server. how can i do this? – Benjamin Nov 12 '19 at 19:53
  • @Benjamin - It is non-typical to allow root to SSH. Are you sure you have performed the required configuration changes to allow root to SSH into the machine? *Check the man output on SCP for proper syntax usage.* – Ramhound Nov 12 '19 at 19:57
  • no i only need a command lijke this ==> send file to another server and this is root pass of server (dont want me a pass in next line) – Benjamin Nov 12 '19 at 19:59

1 Answers1

1

You can use SCP. The syntax is scp local_file server2_user@server_2_ip_address:/path_to_destiny_folder.

Example: cp /etc/rsyslog.conf root@192.65.4.64:/etc/rsyslog.con # copy the rsyslog settings from one server to another.

To automate it via a script you need to generate a ssh keys pair. It will allowed a user login from a server to another without a password. In your case, log as root in server1 and type:

ssh-keygen -t rsa -b 4096

Type enter for all options

cat ~/.ssh/id_rsa.pub

Copy the output command.

login as root in server2 and paste the previous result to the ~/.ssh/authorized_keys file (with it doesn't exist, so create it yourself)

See the full procure at: https://stackoverflow.com/questions/4388385/how-to-ssh-login-without-password