scp is still requesting password - ssh

I want to copy big files from one linux server(SLES11) to another(SunOS) via bash scripting. I dont want to have a password promt so I used ssh-keygen to generate key about this connection.These are the steps I followed:
ssh-keygen -t rsa -b 2048
ssh-copy-id -i /home/username/.ssh/id_rsa.pub swtrans#111.111.111.111
ssh -i id_rsa.pub swtrans#111.111.111.111
After this scp command still requests password.
I am not 'root' user in both servers.
I changed permissions to 700 to the .ssh directory and 640 to the file authorized_keys in the remote server.

ssh -i id_rsa.pub swtrans#111.111.111.111
The -i argument accepts the private key, not the public one. You should use
ssh -i id_rsa swtrans#111.111.111.111
If it will not help, please provide the errors you can see in the server log and in the client

Related

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.

Connect over SSH using a .pem file

I would like to know how to connect over SSH using a .pem file to any server.
Currently I'm executing the following command:
ssh user#mydomain.example
What option should I use?
Use the -i option:
ssh -i mykey.pem user#mydomain.example
As noted in this answer, this file needs to have correct permissions set. The ssh man page says:
SSH will simply ignore a private key file if it is accessible by others.
You can change the permissions with this command:
chmod go= mykey.pem
That is, set permissions for group and others equal to the empty list of permissions.
chmod 400 mykey.pem
ssh -i mykey.pem user#mydomain.example
Will connect you over SSH using a .pem file to any server.
For AWS if the user is ubuntu use the following to connect to remote server.
chmod 400 mykey.pem
ssh -i mykey.pem ubuntu#your-ip
To connect from Terminal to AWS AMI:
chmod 400 mykey.pem
ssh -i mykey.pem ec2-user#mydomain.example
You can connect to a AWS ec-2 instance using the following commands.
chmod 400 mykey.pem
ssh -i mykey.pem username#your-ip
by default the machine name usually be like ubuntu since usually ubuntu machine is used as a server so the following command will work in that case.
ssh -i mykey.pem ubuntu#your-ip
If you still got error messages like:
Received disconnect from 34.219.50.0 port 22:2: Too many authentication failures. Disconnected from 34.219.50.0 port 22
Edit your SSH config located at ~/.ssh/config and add new record at the end
Host mydomain.example
User ubuntu
IdentityFile /home/you/path-to-pem/key.pem
IdentitiesOnly yes
Call short command: ssh mydomain.example
what resolved it for me was to run: sudo chown $USER: {.pem_file}

Avoid to insert path of SSH key pair when connecting through passwordless login

I've set a passwordless connection through ssh using SSH key pair.
So if I run the command:
ssh -i /root/.ssh/root_master master#ip
I'm able to connect to master#ip without typing the pwd.
However I would like to connect without typing
-i /root/.ssh/root_master
but just typing
ssh master#ip
Can anyone help me?
localHost $ ssh remotePassword#remoteHostname
If you want to connect to remote server just by typing above command; you must create ssh trust between your local host and remote host.
Step 1: Create ssh setup on both the host. ( usually, .ssh directory is present at ~ directory )
Step 2: Generate RSA key pair on both the hosts. To generate RSA key pair
cd ~; mkdir -p .ssh; cd .ssh
ssh-keygen -t rsa -f "id_rsa" -N "\" -P "\"; chmod 400 id_rsa
touch authorized_keys; touch known_hosts
Step 3: Write id_rsa.pub file of local host to authorized_keys file of remote host and vice-versa (in case, you want to build both sides trust)
Step 4: Also make entry into known_hosts file or it will automatically create when you will connect for the first time.
This way you can create ssh trust between host and so make them passwordless.
Another way to do this is to usee new ssh module of perl.

Cmd syntax to remotely execute a command through SSH

I would like to start up an application server that resides on another linux machine in another network, so SSH is required. How can I do it? Something like this?:
ssh user#host password /home/user/server/bin/run.sh
?
You can generate a ssh public/private key pair using ssh-keygen command, and then append your public key to .ssh/authorized_keys file of target host, then you can omit the 'password' part above.
ssh-keygen -t rsa
scp .ssh/id_rsa.pub user#host:.ssh/authorized_keys
ssh user#host
chmod og-rw .ssh/authorized_keys
chmod a-x .ssh/authorized_keys
chmod 700 .ssh

cygwin ssh no putty yes?

I generated a keys with putty w/ no passphrase. putty works fine, but now i installed cygwin and would like to use ssh to login. For some reason i'm prompted for a passphrase? why? putty just logs straight in? i don't want to have to generate a new key and annoy the network admins. here is what it looks like in cygwin:
$ ssh -i Documents\ and\ Settings/xxxxx/My\ Documents/xxxxx\ putty\ keys/private\ key.ppk dev.xxxxxx.com
Enter passphrase for key 'Documents and Settings/xxxxx/My Documents/xxxxx putty keys/private key.ppk':
Permission denied (publickey).
Putty uses its own .ppk format for keyfiles, and Cygwin's ssh probably can't read them correctly.
Solution: convert the .ppk file to OpenSSH key format with puttygen.exe.
You need to get "puttygen.exe" from the putty webpage http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html to convert your key to the OpenSSH format. Then it should just work.
If you can login with putty, there is no need to "annoy the network admins". Just generate a new key with cygwin, then login with putty and place your new public key in your .ssh/authorized_keys file. You should now be able to login with cygwin's ssh.
EDIT:
By the way, a sure way to "piss off" any admin is to use unencrypted keys.
You can export PuTTY keys to OpenSSH format and append them to your .ppk file, so that it becomes a valid key for ssh-add.
Just export the private key with PuTTYGen then add it to the .ppk file, then you should be able to ssh-add it. But note that when you edit the .ppk itself with PuTTYGen, it will ovewrite the file.
You can also use a script like this for adding a .ppk file into your SSH agent:
file=~/`basename $0`.tmp
trap "rm -v $file" EXIT
echo -n "Password: "
read -s pwd
echo $pwd | puttygen -P -q -O private-openssh $1 -o $file
ssh-add $file
Source: http://bazaar.launchpad.net/~renatosilva/+junk/scripts/view/head:/ppk-add.sh