Posted: . At: 9:48 PM. This was 8 years ago. Post ID: 8562
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

Cool way to get large files onto a remote server with an SSH connection.

If you are using a remote server with SSH and you wish to get a large file off the Internet to the remote server easily, you may use the wget command to download it directly to the server instead of having to download it at home and then upload it again. That is silly. Use the wget command like this to fetch the file.

ubuntu ~ $ wget https://cdn.kernel.org/pub/linux/kernel/v4.x/testing/linux-4.4-rc5.tar.xz

This makes much more sense than the aforementioned method of downloading and then uploading files. Remote Windows servers with web upload forms I am looking at you. Just right-click on the link and choose “Copy Link Location”, then paste it into the terminal as shown above and download the file directly to the remote server. Nice huh? This makes things much easier and faster. I have tried to upload large files to a Windows server online using the web upload forms, but it would just give an error once it got to 90% uploaded. This way works much better. An SSH connection is preferable for any kind of remote administration. Linux is a multi-user operating system and it is meant to be used over a network. The Internet is perfect for this, connecting over this worldwide network to a machine in another country seems like magic, but it does work.

There is a nice man page for SSH here, this explains everything that you need to know to get your head around using this to securely connect to remote machines.

Some useful Linux networking commands.

This command will return only the IP address of the host. Very useful in a script.

ubuntu ~ $ hostname -i
172.31.20.16

Querying for all local IP addresses on the host.

ubuntu ~ $ hostname -I
172.31.20.16 10.8.0.1

This simple script will ping Google and will check the return value of the ping command to see if the Internet is up or not.

Use this function in your ~/.bashrc file.

function check {
	code=$1;
	if [
		"$code" -ne "0"
	]; then echo "Error failure: code $code "; echo "fail"; fi; 
}

Then run a program and you can check if it worked or not.

ping -c 1 google.com

Then we can check the return value with our function.

check $?

The $? variable in bash will contain the return value of the program you last ran.

┌──[jason@11000000.10101000.00000001.00000011][~]
└──╼  ╼ $ echo $?
0

This is yet another way to get IP address information from the host. This lists active IP addresses on the host network adapters.

ubuntu ~ $ ip a | grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 172.31.20.16/20 brd 172.31.31.255 scope global eth0
    inet6 fe80::4d6:3aff:fea8:8213/64 scope link
    inet 10.8.0.1 peer 10.8.0.2/32 scope global tun1194

The nslookup command is used to retrieve DNS information about a certain host. This returns the DNS servers that service that website/host.

ubuntu ~ $ nslookup facebook.com
Server:         172.31.0.2
Address:        172.31.0.2#53
 
Non-authoritative answer:
Name:   facebook.com
Address: 173.252.120.6

Use netstat to list all Internet connections from your machine. Here I am listing all of the listening connections on my cloud instance.

ubuntu ~ $ netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:mysql         *:*                     LISTEN
tcp        0      0 *:ssh                   *:*                     LISTEN
tcp        0      0 *:https                 *:*                     LISTEN
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN
udp        0      0 *:bootpc                *:*
udp        0      0 *:10995                 *:*
udp        0      0 *:2302                  *:*
udp        0      0 *:2303                  *:*
udp        0      0 *:2304                  *:*
udp        0      0 *:2305                  *:*
udp6       0      0 [::]:13242              [::]:*
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     SEQPACKET  LISTENING     1171791  /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     73100    @/com/ubuntu/upstart
unix  2      [ ACC ]     STREAM     LISTENING     8809     /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     9104     /var/run/acpid.socket
unix  2      [ ACC ]     STREAM     LISTENING     640253   /var/run/mysqld/mysqld.sock

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.