Questions tagged [ssh]

GENERAL SSH SUPPORT IS OFF-TOPIC. Support questions may be asked on https://superuser.com. Secure Shell (SSH) is a cryptographic network protocol for secure data communication. Use this tag for programming questions related to Secure Shell. Common authentication and configuration problems are off-topic for Stack Overflow.

Secure Shell (SSH) is a cryptographic network protocol for secure data communication, remote shell services or command execution and other secure network services between two networked computers that it connects via a secure channel over an insecure network: a server and a client (running SSH server and SSH client programs, respectively). The protocol specification distinguishes two major versions that are referred to as SSH-1 and SSH-2.

SSH was designed as a replacement for Telnet and other insecure remote shell protocols such as the Berkeley rsh and rexec protocols, which send information, notably passwords, in plaintext, rendering them susceptible to interception and disclosure using packet analysis. The encryption used by SSH is intended to provide confidentiality and integrity of data over an unsecured network, such as the Internet, although files leaked by Edward Snowden indicate that the National Security Agency can sometimes decrypt SSH.

SSH uses public-key cryptography to authenticate the remote computer and allow it to authenticate the user, if necessary. There are several ways to use SSH; one is to use automatically generated public-private key pairs to simply encrypt a network connection and then use password authentication to log on.

Another is to use a manually generated public-private key pair to perform the authentication. This method allows users or programs to log in without having to specify a password. Anyone can produce a matching pair of different keys (public and private). The public key is placed on all computers that must allow access to the owner of the matching private key (the owner keeps the private key secret). Although authentication is based on the private key, the key itself is never transferred through the network during authentication. SSH only verifies whether the same person offering the public key also owns the matching private key.

In all versions of SSH it is important to verify unknown public keys, i.e. associate the public keys with identities, before accepting them as valid. Accepting an attacker's public key without validation will authorize an unauthorized attacker as a valid user.

Useful Links

Server Implementations

Client Implementations

Libraries

29979 questions
138
votes
6 answers

How do I set $PATH such that `ssh user@host command` works?

I can't seem to set a new $PATH such that it is used when executing commands via ssh user@host command. I have tried adding export PATH=$PATH:$HOME/new_path to ~/.bashrc and ~/.profile on the remote machine, but executing ssh user@host "echo…
Denver Gingerich
  • 1,587
  • 2
  • 12
  • 6
138
votes
10 answers

write a shell script to ssh to a remote machine and execute commands

I have two questions: There are multiple remote linux machines, and I need to write a shell script which will execute the same set of commands in each machine. (Including some sudo operations). How can this be done using shell scripting? When…
Balanivash
  • 6,709
  • 9
  • 32
  • 48
134
votes
9 answers

Select private key to use with Git

I have 2 Git servers that require 2 different SSH keys. git clone user1@server1:blahblahblah uses ~/.ssh/id_rsa, but I need to specify which key to use depending on the server I am connecting to. What Git command-line parameter does this job? (I am…
user349302
  • 3,491
  • 7
  • 27
  • 31
131
votes
10 answers

Cannot push to Heroku because key fingerprint

I am new to Rails, and I was trying to deploy a very simple app to Heroku. This is the second app that I deploy, and the first one I was able to do it just fine. However I am having some issues with this one. Whenever I "git push heroku master", I…
mre
  • 1,393
  • 2
  • 10
  • 7
129
votes
12 answers

"Invalid privatekey" when using JSch

I'm using the following code to work with Git in a Java application. I have a valid key (use it all the time), and this specific code has work for me before with the same key and git repository, but now I get the following exception: invalid…
o_b7
  • 1,357
  • 2
  • 10
  • 7
129
votes
8 answers

Passing variables in remote ssh command

I want to be able to run a command from my machine using ssh and pass through the environment variable $BUILD_NUMBER Here's what I'm trying: ssh pvt@192.168.1.133 '~/tools/myScript.pl $BUILD_NUMBER' $BUILD_NUMBER is set on the machine making the…
Fergal
  • 5,213
  • 6
  • 35
  • 44
128
votes
5 answers

Open file via SSH and Sudo with Emacs

I want to open a file inside Emacs which is located on a remote server, with sudo powers on the server. I can open local files with sudo via Tramp like this: C-x C-f /sudo::/home/user/file But I want to use sudo on the server: C-x C-f…
Fernando Briano
  • 7,699
  • 13
  • 58
  • 75
128
votes
31 answers

connect to host localhost port 22: Connection refused

While installing hadoop in my local machine , i got following error ssh -vvv localhost OpenSSH_5.5p1, OpenSSL 1.0.0e-fips 6 Sep 2011 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug2: ssh_connect:…
Surya
  • 3,408
  • 5
  • 27
  • 35
127
votes
19 answers

Why doesn't my SSH key work for connecting to github?

Note: I'm not a newb, and I've done this a gazillion times, but for some reason today it decided not to work. I keep getting the Permission denied (publickey). error message when trying to connect to github via SSH or when trying to clone a repo,…
trusktr
  • 44,284
  • 53
  • 191
  • 263
126
votes
2 answers

git - diff of current changes before committing

I have changed several files in a git repository, but have not committed them yet. I can get a list of the changes by just invoking git status. But how do I get a listing of the lines or the content that I have changed, in addition to the…
kikito
  • 51,734
  • 32
  • 149
  • 189
125
votes
3 answers

How to close this ssh tunnel?

I opened a ssh tunnel as described in this post: Zend_Db: How to connect to a MySQL database over SSH tunnel? But now I don't know what I actually did. Does this command affect anything on the server? And how do I close this tunnel, because now I…
Jacob
  • 1,763
  • 2
  • 11
  • 13
122
votes
2 answers

ssh breaks out of while-loop in bash

I use this bash-code to upload files to a remote server, for normal files this works fine: for i in `find devel/ -newer $UPLOAD_FILE` do echo "Upload:" $i if [ -d $i ] then echo "Creating directory" $i ssh $USER@$SERVER…
Robby75
  • 3,285
  • 6
  • 33
  • 52
122
votes
8 answers

How to execute ssh-keygen without prompt

I want to automate generate a pair of ssh key using shell script on Centos7, and I have tried yes "y" | ssh-keygen -t rsa echo "\n\n\n" | ssh-keygen... echo | ssh-keygen.. all of these command doesn't work, just input one 'enter' and the shell…
Jeremy Wang
  • 1,495
  • 3
  • 13
  • 19
122
votes
23 answers

How to fix request failed on channel 0

When I want to connect to my server like this ssh -a username@my-server.de -p 22 it gives me two error messages: PTY allocation request failed on channel 0 shell request failed on channel 0 When I use the parameter -T the first error message goes…
user1895268
  • 1,559
  • 3
  • 11
  • 23
122
votes
9 answers

How can I force ssh to accept a new host fingerprint from the command line?

I'm getting the standard WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that the RSA host key…
John O
  • 4,863
  • 8
  • 45
  • 78