Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Simple port forwarding using SSH

Answer:

Assume you are working at office, you want to browse the facebook.com securely, you can do so by using a computer at home to build a secure tunnel using ssh.

# sudo ssh -L 8080:facebook.com:80

Then in your browser, type http://localhost:8080 and you can view the facebook.com.

Use an alternative port when connecting to remote server using SSH

Answer:

Sometimes the SSH server port is not the standard 22 for security reason. So when you connect it, you need to specify the alternative port used with the -p argument.

E.g.

# ssh -p 12345 john@example.com

Fix the warning of: Remote Host Identification Has Changed error and solution

Answer:

You might experience this error, especially when you are connecting to a remote Linux machine which has just got re-installed.

To solve this, enter the command:

# ssh-keygen -R 192.168.2.36

Where 192.168.2.36 is the IP you are connecting.

Specify a port with the scp command

Answer:

If you want to use scp to copy file to remote machine, but that ssh server is listening at port other than 22, you can use the following command syntax.

# scp -P 6000 test.txt john@remoteserver:/home/john/

Please notes it is -P, not -p.

How to transfer your identity.pub to the remote machine’s authorized_keys?

Answer:

While you can ssh into the remote machine and edit the authorized_keys file, it is easier with the following command.

# ssh-copy-id -i identity-rsa-dsa.pub user@remote-server