Useful SSH tricks for downloading files from an SSH server to your machine.

Posted: July 14, 2014. At: 10:53 AM. This was 3 years ago. Post ID: 7514

This is how to connect to a machine with an SSH server installed and download a file from that machine to your local computer. The sftp command allows this to be accomplished with ease.

Administrator@WIN-EM8GK0ROU41 ~
$ sftp -P 443 homer@
LMDE MATE Editionhomer@'s password:
Connected to
Fetching /home/homer/Documents/my2.c to my2.c

Here is another example that is using wildcards.

Administrator@WIN-EM8GK0ROU41 ~
$ sftp -P 443 homer@*.c
LMDE MATE Editionhomer@'s password:
Connected to
Fetching /home/homer/Documents/hello.c to hello.c
/home/homer/Documents/hello.c                                                                                                                      100%   62     0.1KB/s   00:00
Fetching /home/homer/Documents/multicol.c to multicol.c
/home/homer/Documents/multicol.c                                                                                                                   100%   10KB  10.3KB/s   00:01
Fetching /home/homer/Documents/my.c to my.c
/home/homer/Documents/my.c                                                                                                                         100%  566     0.6KB/s   00:00
Fetching /home/homer/Documents/my2.c to my2.c
/home/homer/Documents/my2.c                                                                                                                        100% 1420     1.4KB/s   00:00
Fetching /home/homer/Documents/randimg.c to randimg.c
/home/homer/Documents/randimg.c                                                                                                                    100%   15KB  14.9KB/s   00:01
Fetching /home/homer/Documents/rot13.c to rot13.c
/home/homer/Documents/rot13.c                                                                                                                      100%  296     0.3KB/s   00:00
Fetching /home/homer/Documents/self.c to self.c
/home/homer/Documents/self.c                                                                                                                       100%  210     0.2KB/s   00:00
Fetching /home/homer/Documents/time.c to time.c
/home/homer/Documents/time.c                                                                                                                       100%  802     0.8KB/s   00:01
Fetching /home/homer/Documents/tune.c to tune.c
/home/homer/Documents/tune.c                                                                                                                       100% 1321     1.3KB/s   00:00
Fetching /home/homer/Documents/x11.c to x11.c

Use the lastlog command to view all logins on the server machine.

homer@deusexmachina ~ $ lastlog
Username         Port     From             Latest
root                                       **Never logged in**
daemon                                     **Never logged in**
bin                                        **Never logged in**
sys                                        **Never logged in**
sync                                       **Never logged in**
games                                      **Never logged in**
man                                        **Never logged in**
lp                                         **Never logged in**
mail                                       **Never logged in**
news                                       **Never logged in**
uucp                                       **Never logged in**
proxy                                      **Never logged in**
www-data                                   **Never logged in**
backup                                     **Never logged in**
list                                       **Never logged in**
irc                                        **Never logged in**
gnats                                      **Never logged in**
nobody                                     **Never logged in**
libuuid                                    **Never logged in**
avahi-autoipd                              **Never logged in**
messagebus                                 **Never logged in**
usbmux                                     **Never logged in**
ntp                                        **Never logged in**
avahi                                      **Never logged in**
colord                                     **Never logged in**
dnsmasq                                    **Never logged in**
pulse                                      **Never logged in**
rtkit                                      **Never logged in**
saned                                      **Never logged in**
davfs2                                     **Never logged in**
mdm                                        **Never logged in**
hplip                                      **Never logged in**
homer            pts/1      Mon Jul 14 10:38:15 +1000 2014
sshd                                       **Never logged in**

This is another way to get this information. The w command is a way to list all active logins.

homer@deusexmachina ~ $ w
 10:40:55 up  1:06,  3 users,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
homer    tty8     :0               19:36     ?     1:19   0.01s /bin/sh /etc/xdg/xfce4/xinitrc -- /etc/X11/xinit/xserverrc
homer    pts/0    :0.0             09:46   54:39   0.11s  0.11s bash
homer    pts/1      10:38    7.00s  0.13s  0.00s w

Finally; this command will list all active logins.

homer@deusexmachina ~ $ finger -lmps
Login: homer                            Name: John Cartwright
Directory: /home/homer                  Shell: /bin/bash
On since Mon Jul 14 19:36 (EST) on tty8 from :0 (messages off)
On since Mon Jul 14 09:46 (EST) on pts/0 from :0.0
   56 minutes idle
On since Mon Jul 14 10:38 (EST) on pts/1 from
No mail.

To login to a specific port on an SSH server; use this command.

ssh user@ -p 443

This will login to the SSH server using port 443. This is very useful if you want to use this port to allow SSH access through a firewall that blocks port 22.

No comments have been made. Use this form to start the conversation :)

Leave a Reply