SSH 'command not found' when trying to connect to AWS - ssh

I'm new to Amazon web services and have managed to set up an instance.
I already have the ssh directory on my machine at: /usr/bin/ssh
I have also downloaded a Pem key file to my machine and have tried to copy my Pem key file into that directory but I cannot navigate to it. When I try:
cd /usr/bin/ssh
I get:
-bash: cd: /usr/bin/ssh: Not a directory
When I just try to type the command:
ssh
I get the following:
BEGIN: command not found
: command not found2: MIIEpAIBAAKCAQEAu6JORnapcVdvAwPm+6LVBA3n8chlGU4nE0g9nyD8zSDWlATJpf1Td35tPrxj
: No such file or directory
can anyone help with this?
I'm on OSX Lion 10.8.4 if that helps!

Your problem appears to be related to configuring the ssh keys. First, some clarifications:
/usr/bin/ssh is not a directory, it is the actual secure shell program. Do not modify it. (If you have already destroyed your ssh installation, you would need to restore the installation: http://support.apple.com/kb/PH10763).
ssh will use a public and a private key (keypair) to authenticate. The private key should be stored locally on your computer, generally in the .ssh folder inside your home directory (~/.ssh)
You may have generated the keypair yourself, or have gotten one generated by AWS.
I will assume your .pem file is the private key portion of the keypair, and that you have downloaded that from AWS after following a procedure along the lines of: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/how-to-have-aws-create-the-key-pair-for-you.html.
In that case, you need to simply:
copy the .pem file into your ~/.ssh directory.
rename it to id_rsa
ensure that you have correctly set permissions for the private key and .ssh directory (ssh is picky), typically 600 for the id_rsa file and 700 for the .ssh directory.
initiate the ssh connection via ssh username#host

Related

cannot find id_ed25519 private and public key file in the ssh file folder

I'm new to ssh and having some trouble with it.
I need to connect my pycharm on my windows10 to the remote server using OpenSSH and the private key in Tools->deployment->configuration, but now I can't see id_ed25519 or id_ed25519.pub file in the ssh file folder.
I have generated an Ed25519 key by using the following code:
cd ~
ssh-keygen -t ed25519
I can find my private and public key by the following command:
cd .ssh
ls
#return: id_ed25519 id_ed25519.pub id_rsa id_rsa.pub known_hosts
I'm wondering why the private and public key disappeared, or if they were stored somewhere else. But I can find other files returned by the command above.
I even successfully connected to my remote server using the pubkey.
Is there any solution?
I have found the answer!
I generated the key more than once. And every time I needed to copy the key to Windows file system with the following command.
cd /mnt/c/users/<my-account>/.ssh/
I have two accounts, one for personal utility, the other for work. That was where I made a mistake. I filled the wrong account in the <my-account>. That is to say, I logged into the other.
That's really silly.

How can I perform a strict host key checking using JSch

I am trying to connect to a server using JGit. I can connect successfully using the following setting
JSch.setConfig("StrictHostKeyChecking", "no");
The problem is that I actually want a strict host key checking. So I replaced the previous line with the following:
JSch.setConfig("StrictHostKeyChecking", "yes");
But now it doesn't work. My certificates a located in a folder called .ssh located in my home directory. The names of the files are id_rsa and id_rsa.pub. In the server (that has Linux) I have a file called authorized_keys located in ~/.ssh which has the same content as id_rsa.pub.
The code was actually ok. The problem is that you have to do the following things:
These operation must be performed on you client computer.
1) Create a folder named .ssh in you home directory (for example C:\Users\John)
2) Enter the new folder and create the certificates using git bash with the following command
ssh-keygen -t rsa -m PEM
The certificates are 2 files named id_rsa and id_rsa.pub
3) Type the following command (always using git bash):
ssh-keyscan -t rsa ip_address_of_your_server >> ~/.ssh/known_hosts
It will create a file called known_hosts. So eventually in the .ssh folder of the client there will be 3 files: id_rsa, id_rsa.pub and known_hosts.
Now go to you server computer and do the following
1) Create a folder named .ssh in you home directory (for example ~/John)
2) Enter there and create a file named authorized_keys and copy the content of the file id_rsa.pub inside this new file
3) Find the file etc/ssh/sshd_config
4) Make sure that the following 2 lines are present and uncommented
PubKeyAuthentication yes
PasswordAuthentication no
5) Save the file and restart sshd
sudo systemctl restart sshd

Change SSH pem file

I want to change my remote server SSH. Currently I login through a .pem file
ssh -l ubuntu -i .ssh/myfile.pem XX.XX.XXX.XXX
I tried to find how to change that access key but I found only that methor :
ssh-keygen -t rsa -b 2048
cp id_rsa.pub authorised_keys
scp authorized_keys ubuntu#XX.XX.XXX.XXX:/home/ubuntu/.ssh
I see no .pem file generated, plus how can I connect now ?
I want to make sure before I do anything so I don't lose ability to connect via SSH.
Should I remove the old key with :
ssh-keygen -R hostname
If yes, when ? after or before the scp ? if after this will remove both keys, if before then I wouldn't be able to perform scp !!!
I am a bot confused.
I see no .pem file in my remote, the pem file is only in my local .ssh folder. in remote .ssh I see :
With "ssh-keygen" command you generate a pair of public and private keys (by default stored in $HOME/.ssh).
Then you copy the public key in your remote server, and the private key in your local client (with permissions 0600). You can use "ssh-add" command to add the private key to the authentication agent to be able to connect to the remote server.

Failure to authenticate SSH keys

I'm in the process of setting up a virtual server via Amazon AWS. I followed their tutorial regarding setting up a Linux based virtual server on OS X. Everything goes well until I get to the .ssh pair key file. I download AWS's key as a .pem file. It saves as a .pem.txt file. Which seems odd from what I'm reading. So, I duplicate and change the extension to .pem only.
Then I go to copy the file from downloads to the ~/.ssh folder and get no problems using cp ~/Downloads/FileName.pem ~/.ssh. When I try to use chmod 400 to adjust the security parameters of the folder it returns "Not a directory". When I try to authenticate it fails. I suspect because it has something to do with the chmod 400 code line, but I'm not certain. I also wanted to verify to make sure the file copied into the .ssh folder, but all of the suggestions online about unhiding the hidden folders on a Mac were a no-go.
It is a Linux set up so the user name is the one listed in the tutorial (I already researched this problem). I double check to see if there was a file .ssh and there seems to be. When I type ssh in the terminal I do get feedback, so I'm assuming there is a file there.
Create an ssh folder in your home folder, if one is not present. Then copy the PEM file to that folder. Then change permissions of the PEM file to protect it. Something like this:
mkdir -p ~/.ssh
cp fred.pem.txt ~/.ssh/fred.pem
chmod 400 ~/.ssh/fred.pem

SSH from Synology NAS to remote server

When I run competitions for Icelandic Horses, I want to automatically upload the results from our Synology NAS to a remote webserver. The program we use automatically generates the html-files that needs to be uploaded.
What is the easiest way to achieve this? I have SSH access on both the NAS and the webserver.
Any help is appreciated :)
In this case you can create a cron task in the synology console with the command:
sudo -i
vi /etc/crontab
Edit the file and add a line like this at the end of the file with a scp command:
0 0 * * * root scp -r "-i/root/.ssh/mykey" 'root#serverurl.com:/some/remote/path' '/some/local/path'
Finally you have to reload the configuration restarting the service with:
synoservice -restart crond
Before all this you must to configure a pair keys to avoid the password entry:
cd to a private directory of the user which will be running the script (typically "$HOME/.ssh", to be created if needed). That directory must be protected to write acces from other users, fix the modes if needed.
generate the keypair using command "ssh-keygen"
("/usr/syno/bin/ssh-keygen" if not in your PATH)
at the prompt "Enter file in which to save the key", choose a file
name (let's say "mykey")
at the prompt "Enter passphrase (empty for no passphrase):" press
return (this will create a passwordless private key)
Two files will be created: "mykey" and "mykey.pub"
copy the contents of mykey.pub inside "$HOME/.ssh/authorized_key"
file of user account on the remote machine your script is going to
connect to.
in your script, add "-i" as argument to the
ssh command
Also in this forum is explained how to make the copy with rsync instead of scp