Essential SSH commands
The following ssh commands are used by me in everyday development activity. So it prompted me to write a blog post about the essential SSH commands during java development.
ssh username@remote-server-host-or-ip
ssh -i /path/to/private-key.pem username@remote-server-host-or-ip
SSH to a remote server with agent forwarding
The following command forwards your SSH auth schema to the remote host. So you can use SSH over there as if you were on your local machine.
ssh -A username@remote-server-host-or-ip
ssh -A -i /path/to/private-key.pem username@remote-server-host-or-ip
The following command forwards traffic
http://localhost:8080 <--> http://remote-server-host-or-ip:9090
http://localhost:8081 <--> http://remote-server-host-or-ip:9091
ssh -L 8080:localhost:9090 -L 8081:localhost:9091 username@remote-server-host-or-ip
curl --insecure -v 'http://localhost:8080/do-some-stuff'
curl --insecure -v 'http://localhost:8081/do-some-other-stuff'
The following command forwards traffic as below with 'first-remote-server-host-or-ip' acting as proxy
http://localhost:8080 <--> http://second-remote-server-host-or-ip:9090
This is particulary helpful in situations where traffic is allowed only through whitelisted servers or IP ranges.
ssh -L 8080:second-remote-server-host-or-ip:9090 username@first-remote-server-host-or-ip
The following commands forwards traffic as given below. This is useful in situations when the application servers can be connected only through jump off servers
http://localhost:8080 <--> http://first-remote-server-host-or-ip:8081
http://first-remote-server-host-or-ip:8081 <--> http://second-remote-server-host-or-ip:8082
ssh -L 8080:localhost:8081 username@first-remote-server-host-or-ip
ssh -L 8081:localhost:8082 username@second-remote-server-host-or-ip
SSH to a remote server using username and password
ssh username@remote-server-host-or-ip
SSH to a remote server with a specific port (other than 22)
ssh username@remote-server-host-or-ip -p 26
SSH to a remote server using private key (or identity file)
ssh -i /path/to/private-key.pem username@remote-server-host-or-ip
SSH to a remote server with agent forwarding
The following command forwards your SSH auth schema to the remote host. So you can use SSH over there as if you were on your local machine.
ssh -A username@remote-server-host-or-ip
ssh -A -i /path/to/private-key.pem username@remote-server-host-or-ip
Setup port forwarding with remote server
The following command forwards traffic
http://localhost:8080 <--> http://remote-server-host-or-ip:9090
http://localhost:8081 <--> http://remote-server-host-or-ip:9091
ssh -L 8080:localhost:9090 -L 8081:localhost:9091 username@remote-server-host-or-ip
curl --insecure -v 'http://localhost:8080/do-some-stuff'
curl --insecure -v 'http://localhost:8081/do-some-other-stuff'
Setup port forwarding to a different server
The following command forwards traffic as below with 'first-remote-server-host-or-ip' acting as proxy
http://localhost:8080 <--> http://second-remote-server-host-or-ip:9090
This is particulary helpful in situations where traffic is allowed only through whitelisted servers or IP ranges.
ssh -L 8080:second-remote-server-host-or-ip:9090 username@first-remote-server-host-or-ip
Setup port forwarding with two tunnels
The following commands forwards traffic as given below. This is useful in situations when the application servers can be connected only through jump off servers
http://localhost:8080 <--> http://first-remote-server-host-or-ip:8081
http://first-remote-server-host-or-ip:8081 <--> http://second-remote-server-host-or-ip:8082
ssh -L 8080:localhost:8081 username@first-remote-server-host-or-ip
ssh -L 8081:localhost:8082 username@second-remote-server-host-or-ip
Comments
Post a Comment