13

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.

17

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 user@rhost.com: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 user@1.2.3.4: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.

  • 1
    What if the command returns "ifconfig: interface eth0 does not exist"? – kolistivra Nov 19 '14 at 14:45
  • 1
    @kolistriva Try "en0". – Lyle Oct 20 '16 at 21:13
6

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"
  • 2
    No need to log in and out, just type last -ai. – joelostblom Jan 25 '17 at 8:46
4

I just got the fastest 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

  • 4
    Or echo $SSH_CLIENT silghtly longer to type but almost no clutter to read. – dave_thompson_085 Dec 28 '16 at 16:16
2

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

1

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

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.