23

I'm on a macbook running Lion. In Terminal I'm connected to my schools server with ssh. I navigated to a folder on the server and have a file I want to copy to my local machine, but I don't know what the IP address of my local machine is. How can I get it? I'm in the folder on the server, and I want to copy read.txt onto my local machine's hard drive. I've tried scp ./read.txt [my computer name].local/newRead.txt but it doesn't work.

Marty
  • 897
  • 2
  • 8
  • 14

5 Answers5

23

You don't need to know your own host's IP address in order to copy files to it. Simply use scp to copy the file from the remote host:

$ scp [email protected]:path/to/read.txt ~/path/to/newRead.txt

If you want to copy to your local host from your remote host, get your own IP address with ifconfig and issue the following:

$ scp path/to/read.txt [email protected]:path/to/newRead.txt

where 1.2.3.4 is your local IP address. A convenient way to extract a host's IP address is using this function:

ipaddr() { (awk '{print $2}' <(ifconfig eth0 | grep 'inet ')); }

where eth0 is your network interface. Stick it in ~/.bash_profile in order to run it as a regular command - ipaddr.

10

I just got the shortest way around this

$ who

root     pts/22       2016-12-28 13:22 (179.xx.xxx.xx)

If connected via ssh. This will display the user logged in plus the IP address

Radiumrasheed
  • 101
  • 1
  • 5
8

Just adding to the answer, an easy way to tell your address (ip/domain), is to ssh into a computer you can ssh into, exit and then ssh back into it again. Most times, you'll see a welcome message like:

"Last login at xx:xxpm from you.domain.com/ip.ad.dre.ss"
Olumide
  • 81
  • 1
  • 1
3

Try ifconfig. It should tell you your local IP address (on your network) for the various interfaces like WiFi and Ethernet.

Naftuli Kay
  • 38,686
  • 85
  • 220
  • 311
2

An easiest way to get IP address via SSH:

Command: ifconfig

Example:

stalinrajindian@ubuntuserver:~$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.30.3.27  netmask 255.255.255.0  broadcast 172.30.3.255
        inet6 fe80::a00:27ff:fe8b:9986  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:8b:99:86  txqueuelen 1000  (Ethernet)
        RX packets 4876  bytes 1951791 (1.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 775  bytes 73783 (73.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 78  bytes 5618 (5.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 78  bytes 5618 (5.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0