Posts Tagged Redes

Using SSH

SSH

If you are working in a networking environment, more likely you’ll need servers, run commands or copy files remotely and safely. For this you count on with the ssh protocol which allows you exchange data between devices through a secure channel, using public key cryptography to authenticate remote computers and users. Some features that offers ssh are:

  • It allows you to mange computer remotely.
  • It can be used as an FTP alternative (using SFTP).
  • It the replacement of the r commands (rcp, rsh, rlogin and telnet).
  • It allows you to redirect ports and tunneling.
  • It can be used to run commands on remote servers.
  • It allows to run graphical applications in a remote server and display them in the local computer.
  • By default it listens on the TCP port 22.

Installing SSH

On Debian you can install the server and the client as follow:

aptitude install openssh-client openssh-server

Accessing remote servers

In order to access a remote server using an IP address, you can do the following:

ssh user@server.com
ssh user@192.168.1.30

Where server.com must be a address associated to an IP address by and DNS or through the /etc/hosts file. In the other hand, if the current account exists in server and client, you can omit the user name and the current working user will be assumed:

ssh 192.168.1.30

Running commands remotely

In order to run a command remotely, you can use this syntax:

ssh user@server.com command
ssh user@192.168.1.30 command

Where command refers to the command or absolute path of the program to run. Examples:

ssh user@server.com /usr/local/bin/backup
ssh user@192.168.1.30 ls > listing.tx

Running graphical applications remotely

Sometimes you need to run graphical applications  on remote server but display them on locally. You can achieve this with ssh by using the -X switch:

ssh -X user@server.com application
ssh -X user@192.168.1.30 application

For instance, if you want to run Firefox from a remote server you can type the following:

ssh -X lgallard@192.168.1.30 firefox

Note: In order to display graphical applications remotely, the client must enable the following option in the /etc/ssh/sshd_config file:

X11Forwarding yes

Copying files remotely

Sooner or later you will need to copy files among working stations and, to avoid  copy them on temporary media (like pendrives), you can copy directly from one device to another. To do so, follow this syntax:

Copy from a local computer to a remote server:

scp /local/path/to/file user@server.com:/remote/path
scp /local/path/to/file user@192.168.1.30:/remote/path

Example:

scp /etc/passwd lgallard@192.168.1.30:/home/lgallard/Desktop

Copying from a remote server to a local computer::

scp user@server.com:/remote/path/to/file /local/path
scp 192.168.1.30:/remote/path/to/file /local/path

Example:

scp root@192.168.1.30:/etc/shadow .

References


,

3 Comments