Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ssh-keygen
- ssh-copy-id user@host
- ## or if your server uses custom port no:
- ssh-copy-id "user@host -p 1234"
- ssh user@host
- not-marco@rinzwind-desktop:~$ ssh-keygen
- Generating public/private rsa key pair.
- Enter file in which to save the key (/home/not-marco/.ssh/id_rsa):
- Created directory '/home/not-marco/.ssh'.
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /home/not-marco/.ssh/id_rsa.
- Your public key has been saved in /home/not-marco/.ssh/id_rsa.pub.
- The key fingerprint is:
- b1:25:04:21:1a:38:73:38:3c:e9:e4:5b:81:e9:ac:0f not-marco@rinzwind-desktop
- The key's randomart image is:
- +--[ RSA 2048]----+
- |.o= . oo. |
- |*B.+ . . |
- |*=o . o . |
- | = . = |
- |. o S |
- |E. |
- | o |
- | . |
- | |
- +-----------------+
- not-marco@rinzwind-desktop:~$ ssh-copy-id not-marco@127.0.0.1
- not-marco@127.0.0.1's password:
- Now try logging into the machine, with "ssh 'not-marco@127.0.0.1'", and check in:
- ~/.ssh/authorized_keys
- to make sure we haven't added extra keys that you weren't expecting.
- sshpass -p 'password' ssh your_username@your_server
- #PasswordAuthentication yes
- PasswordAuthentication no
- $ sudo chmod 700 .ssh && chmod 600 .ssh/authorized_keys
- ssh-keygen -b 4096
- Protocol 1,2
- remote=user@remotehost # fill in correct user and remotehost names
- cd $HOME/.ssh
- # create .ssh on remote host if it is non-existing:
- ssh $remote 'if [ ! -d .ssh ]; then mkdir .ssh; fi'
- # copy RSA1 key:
- scp identity.pub ${remote}:.ssh
- ssh $remote "cd .ssh; cat identity.pub >> authorized_keys"
- remote=user@remotehost # fill in correct user and remotehost names
- cd $HOME/.ssh
- # create .ssh on remote host if it is non-existing:
- ssh $remote 'if [ ! -d .ssh ]; then mkdir .ssh; fi'
- # copy DSA key:
- scp id_dsa.pub ${remote}:.ssh
- ssh $remote "cd .ssh; cat id_dsa.pub >> authorized_keys2"
- #!/bin/sh
- # create ssh connections without giving a password
- if [ $# -lt 1 ]; then
- echo Usage: $0 username@remotehost
- exit
- fi
- remote="$1" # 1st command-line argument is the user@remotehost address
- this=$HOST # name of client host
- # first check if we need to run ssh-keygen for generating
- # $HOME/.ssh with public and private keys:
- if [ ! -d $HOME/.ssh ]; then
- echo "just type RETURN for each question:" # no passphrase - unsecure!!
- # generate RSA1, RSA and DSA keys:
- echo; echo; echo
- ssh-keygen
- echo; echo; echo
- ssh-keygen -t rsa
- echo; echo; echo
- ssh-keygen -t dsa
- else
- # we have $HOME/.ssh, but check that we have all types of
- # keys (RSA1, RSA, DSA):
- if [ ! -f $HOME/.ssh/identity ]; then
- # generate RSA1 keys:
- echo "just type RETURN for each question:" # no passphrase - unsecure!!
- ssh-keygen
- fi
- if [ ! -f $HOME/.ssh/id_rsa ]; then
- # generate RSA keys:
- echo "just type RETURN for each question:" # no passphrase - unsecure!!
- ssh-keygen -t rsa
- fi
- if [ ! -f $HOME/.ssh/id_rsa ]; then
- # generate DSA keys:
- echo "just type RETURN for each question:" # no passphrase - unsecure!!
- ssh-keygen -t dsa
- fi
- fi
- cd $HOME/.ssh
- if [ ! -f config ]; then
- # make ssh try ssh -1 (RSA1 keys) first and then ssh -2 (DSA keys)
- echo "Protocol 1,2" > config
- fi
- # copy public keys (all three types) to the destination host:
- echo; echo; echo
- # create .ssh on remote host if it's not there:
- ssh $remote 'if [ ! -d .ssh ]; then mkdir .ssh; fi'
- # copy RSA1 key:
- scp identity.pub ${remote}:.ssh/${this}_rsa1.pub
- # copy RSA key:
- #scp id_rsa.pub ${remote}:.ssh/${this}_rsa.pub
- # copy DSA key:
- scp id_dsa.pub ${remote}:.ssh/${this}_dsa.pub
- # make authorized_keys(2) files on remote host:
- echo; echo; echo
- # this one copies all three keys:
- #ssh $remote "cd .ssh; touch authorized_keys authorized_keys2; cat ${this}_rsa1.pub >> authorized_keys; cat ${this}_rsa.pub >> authorized_keys2; cat ${this}_dsa.pub >> authorized_keys2;"
- # this one copies RSA1 and DSA keys:
- ssh $remote "cd .ssh; touch authorized_keys authorized_keys2; cat ${this}_rsa1.pub >> authorized_keys; cat ${this}_dsa.pub >> authorized_keys2;"
- echo; echo; echo
- echo "try an ssh $remote"
- curl https://raw.github.com/beautifulcode/ssh-copy-id-for-OSX/master/ssh-copy-id.sh -o /usr/local/bin/ssh-copy-id
- chmod +x /usr/local/bin/ssh-copy-id
- ssh-copy-id "not-marco@127.0.0.1 -p 2222"
- ssh-keygen
- ssh-copy-id -i ~/.ssh/12gpu_server.pub lerner@192.168.20.160
- Host *
- IdentitiesOnly yes
- Host 12gpu
- HostName 192.168.20.160
- User lerner
- IdentityFile ~/.ssh/12gpu_server
Add Comment
Please, Sign In to add comment