SSh - Connect with different username - ssh

I am trying to connect to my university servers via my mac. The servers in question are as follows:
silo.soic.indiana.edu and odic.cs.indiana.edu
When I try using my username, I have no issue in connecting to both the servers and accessing my files. However i am trying to use my friends username (and password, provided by him), and I cant seem to connect to either of the instances. I googled the issues but there are no solutions that I have to work.
When I connect to the servers i use ssh odin.cs.indiana.edu and it automatically detects my username and prompts me with a password. After the password has been entered I am connected to the said instance.
For my friends username I use ssh friend#odin.cs.indiana.edu after which it prompts me for a password. When I enter the password, i get the return Permission denied, please try again. . I used the verbose -v argument to get more info into the process and I get this :
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to odin.cs.indiana.edu [129.79.240.100] port 22.
debug1: Connection established.
debug1: identity file /Users/isharief/.ssh/id_rsa type 1
debug1: identity file /Users/isharief/.ssh/id_rsa-cert type -1
debug1: identity file /Users/isharief/.ssh/id_dsa type -1
debug1: identity file /Users/isharief/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 55:49:2c:08:67:a9:f4:33:99:b1:3b:90:c5:c0:33:32
debug1: Host 'odin.cs.indiana.edu' is known and matches the RSA host key.
debug1: Found key in /Users/isharief/.ssh/known_hosts:7
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/isharief/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/isharief/.ssh/id_dsa
debug1: Next authentication method: password
AFter which I enter the password and I get permission denied. both of us have extremely low skills regarding ssh , keys etc so can someone please give a simple explanation /workaround for this issue?

You are able to log in as you because in the remote server's /home/you/.ssh/authorized_keys your public key is present but it is not there in /home/yourfriend/.ssh/authorized_keys. You need to add the public key to the /home/yourfriend/.ssh/authorized_keys. You can try the following
ssh-copy-id -i yourkey.pub yourfriend#servername
It adds the public key to the /home/yourfriend/.ssh/authorized_keys. But you need your friend's password which he uses to log in to the server. if it doesn't work you need to manually append the key to the /home/yourfriend/.ssh/authorized_keys. If you are manually appending make sure you are appending the key as one single line.
hope it helps. It might resolve the issue but you still can face issues because of the sshd_config file on the remote server. Try the above method and let me know if you are still facing any issue.

Related

adding ssh public key to server

I'm trying to push my id_rsa.pub to server so I can ssh into it.
I've run the following command,
cat ~/.ssh/id_rsa.pub | ssh -v -p 12345 myname#123.45.67.8 'cat >> ~/.ssh/authorized_keys'
which returns the following debugging:
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 123.45.67.8 [123.45.67.8] port 12345.
debug1: Connection established.
debug1: identity file /Users/myname/.ssh/id_rsa type 1
debug1: identity file /Users/myname/.ssh/id_rsa-cert type -1
debug1: identity file /Users/myname/.ssh/id_dsa type -1
debug1: identity file /Users/myname/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.4
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.4 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA [some server host key]
debug1: Host '[123.45.67.8]:12345' is known and matches the RSA host key.
debug1: Found key in /Users/myname/.ssh/known_hosts:6
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/myname/.ssh/github_rsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: /Users/myname/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/myname/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
I can't figure out what the problem is..
can anybody please help me out?
Key based authentication will only work if the authorized_keys has
Correct permissions.
Try to do a chmod 600 ~/.ssh/authorized_keys
Your command will only work if you can ssh to the server by entering a password. It also requires the dir ~/.ssh to be created on the remote server and lastly (as Jan-Erik Revsbech points out) the permissions on the local and the remote ~/.ssh needs to disallow others reading it.
If you instead use ssh-copy-id remote-server to copy your keys, then both the dir and permissions on the remote system will be set correctly. It will still require you to enter the password the first time, though.
Make sure to also set the correct owner :)
I tried ssh-copy-id remote-server as suggested by Ole and got an error like this:
Cannot write to .ssh/authorized_keys. Permission denied
The directory ~/.ssh as well as the file authorized_keys were already present on the server and set up with the right permission... but for the wrong user! Here is, what solved it:
chown right-user:right-user .ssh
chown right-user:right-user .ssh/authorized_keys
I changed the owner of the file and the directory. Then ssh-copy-id worked.

AWS- public key denied on opening ssh

I know there are alot of questions regarding AWS & SSH sessions, and I've attempted to make use of them, but all have failed.
I have an instance running, and the ssh string given by the EC2 Management Console is
ssh -i -v jason.pem ubuntu#ec2-54-227-167-156.compute-1.amazonaws.com
which produces the output
OpenSSH_5.9p1 Debian-5ubuntu1.1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to ec2-54-227-167-156.compute-1.amazonaws.com [54.227.167.156] port 22.
debug1: Connection established.
debug1: identity file jason.pem type -1
debug1: identity file jason.pem-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian- 5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA ea:b6:50:fe:49:49:90:76:03:91:21:6d:73:0e:04:d2
debug1: Host 'ec2-54-227-167-156.compute-1.amazonaws.com' is known and matches the ECDSA host key.
debug1: Found key in /home/jason/.ssh/known_hosts:27
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Trying private key: jason.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
I've done the following:
Created new keypair, downloaded jason.pem and set to 0400 chmod permissions
Added ChallengeResponseAuthentication yes to /etc/ssh/ssh_config
What exactly is going on, and why is the jason.pem file not being accepted?
The public key on your instance doesn't align with your private keypair. If that instance's configuration is important and you want to keep it (I say this based upon the fact that you shutdown the instance rather than just creating a new one):
Create a new keypair
Create an AMI of the instance you want to access
Create a new instance from that AMI using the new keypair
Attempt to ssh into it again using the new downloaded keypair
400 permissions should be fine for the keypair.

ssh to aws permission denied (public key) using ubuntu# why is it failing?

I can't seem to use SSH to connect to AWS although I don't usually have any problems with github or heroku. The debug is below, I've tried #ubuntu and #ec2-user (it should be #ubuntu), I've also tried creating a config file in .ssh (on windows) and adding 'ChallengeResponseAuthentication yes' as that seemed to fix it on another thread, but no luck. I've modified the permissions of the.pem file to 400. I don't understand why it says it all sounds positive but then fails, if I could get a better idea of what the error is I might be able to find a solution. Any help very much appreciated!
$ ssh -v -i futurebot2.pem ubuntu#ec2-54-218-75-37.us-west-2.compute.amazonaws.com
OpenSSH_6.2p2, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /home/Mark/.ssh/config
debug1: Connecting to ec2-54-218-75-37.us-west-2.compute.amazonaws.com [54.218.75.37] port 22.
debug1: Connection established.
debug1: identity file futurebot2.pem type -1
debug1: identity file futurebot2.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA f2:cd:94:4d:a1:9a:b5:67:cb:f7:91:d7:ef:4d:a4:3d
debug1: Host 'ec2-54-218-75-37.us-west-2.compute.amazonaws.com' is known and matches the ECDSA host key.
debug1: Found key in /home/Mark/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: futurebot2.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
Two reasons why this might happen.
User does not exist, this might be due to connecting with the wrong user or an instance that is not your own (wrong ip address)
The user does not have your key in its authorized keys file. In AWS, the key you select at launch is added to your instance, but if you want to use other keys, you need to add them to your authorized_keys file manually.

SSH: localhost closes connection after successful login

When I try to ssh into localhost, it accepts the public key and immediately closes the connection. I've been going through pages of Google results for hours now with no progress. Here's what I get after ssh -v user#localhost:
OpenSSH_5.9p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/user/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /Users/user/.ssh/id_rsa type -1
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: identity file /Users/user/.ssh/id_dsa type 2
debug1: identity file /Users/user/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9
debug1: match: OpenSSH_5.9 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 67:2f:0b:c8:40:e8:87:0f:57:ee:c7:68:ae:8a:5a:02
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /Users/user/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/user/.ssh/id_rsa
debug1: Offering DSA public key: /Users/user/.ssh/id_dsa
debug1: Server accepts key: pkalg ssh-dss blen 433
debug1: read PEM private key done: type DSA
Connection closed by ::1
I'm running OSX 10.8, using ssh through Terminal.
Okay, so what finally worked was explicitly allowing connections from user. Setting System Prefs > Sharing > Remote Login > Allow access for: to All Users doesn't work; instead I had to check Only these users: and manually add all users. Hope this helps anyone else having the same problem.
A long time ago I had the same problem with Telnet, and if I remember it well, the problem was with the user having no home directory in /etc/passwd.
I am assuming that you are trying to create a password-less connection, am I right?
When you google it, there is a good explanation of it here: http://diuf.unifr.ch/main/tech/node/57
Also, here is an explanation how to quickly make the password less connection http://greg-n-blog.blogspot.com/search/label/scp
This worked for me in Cygwin using Windows within a large domain:
Add your Windows user ID to /etc/passwd. You can get it by typing $ mkpasswd -d | grep [username]. In a large domain, you may have to wait several hours.
Make sure the user ID given in /etc/passwd matches that in $ id -u, and the group ID matches that for Administrators in /etc/group

Error while connecting to EC2 instance

Here is the log :
macs-MacBook-Air:~ mac$ ssh -v -i sohoKey.pem ec2-user#ec2-107-22-101-75.compute-1.amazonaws.com
OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug1: Connecting to ec2-107-22-101-75.compute-1.amazonaws.com [107.22.101.75] port 22.
debug1: Connection established.
debug1: identity file sohoKey.pem type -1
debug1: identity file sohoKey.pem-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'ec2-107-22-101-75.compute-1.amazonaws.com' is known and matches the RSA host key.
debug1: Found key in /Users/mac/.ssh/known_hosts:3
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: sohoKey.pem
debug1: Authentications that can continue: publickey
debug1: Trying private key: sohoKey.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).
In AWS console, I saw that my key pair was deleted. I created a new one with the same name. Then I tried to connect with ssh -v -i sohoKey.pem ec2-user#ec2-107-22-101-75.compute-1.amazonaws.com
Creating a keypair with the same name won't help - it's the data in it that counts.
It's also not possible to change the keypair on a running instance, i don't believe there is anything you can do. If there is data that you want to recover from the instance and the volume is an EBS volume then you can mark the volume as not to be deleted on termination. After terminating the instance the volume should be left intact and you'll be able to attach it to a different instance.
You could try bringing up a new instance then disconnecting the storage from the one you have lost the key pair to, and then adding it to the new instance.
Another option, but I haven't tried, is to create a new image out of the current instance. When this is complete, create a new instance of the new image and create a new key pair.
Either way you have lost the ability to connect and you cannot add a new key pair (as far as I know) to an instance.
I detached my EBS Volume from the instance. After that I created a new instance then I attached the 8GB EBS to that.
After that, I mounted that instance to /mybackup.
So I could reach my data from /mybackup/...
Thank you for your suggestions.
But I still don't know, why my key pair has gone?