ssh1 ssh2 how to tell which version i have?

upon entering the command:ssh -v 

I get this:OpenSSH_4.4p1, OpenSSL 0.9.8d 28 Sep 2006

how do i identify whether or not i have ssh1 or ssh2?

thanks in advance


OpenSSH supports both protocols. You can use the options -1 or -2 to specify the protocol. Unless specified otherwise in sshd_config (as explained by glen.barber) the default is to use 2, and if that fails, to try 1.


source - http://www.unix.com/unix-for-dummies-questions-and-answers/86671-ssh1-ssh2-how-tell-version-i-have.html






* 목표

a@A에서 b@B로 패스워드 없이 ssh 접속


* 방법 

A에서 public key 생성 후 이 키를 B의 ~/.ssh/authorized_keys에 등록한다.


* 설정 

1.  ssh-keygen 명령어는 rsa으로 기본 키를 생성한다.

a@A$  ssh-keygen 

Generating public/private rsa key pair.

Enter file in which to save the key (/home/a/.ssh/id_rsa): 

Created directory '/home/a/.ssh'.

Enter passphrase (empty for no passphrase): 

Enter same passphrase again: 

Your identification has been saved in /home/a/.ssh/id_rsa.

Your public key has been saved in /home/a/.ssh/id_rsa.pub.

The key fingerprint is:

70:cd:75:b1:d7:1b:17:18:54:ec:5e:a8:c9:65:d5:d3 a@A

The key's randomart image is:


a@A$ ll ~/.ssh
-rw-------. 1 a a 1.7K 2014-10-03 15:36 id_rsa
-rw-r--r--. 1 a a  390 2014-10-03 15:36 id_rsa.pub


2. 생성된 public key를 B의 ~/.ssh/authorized_keys에 등록

b@B$ mkdir ~/.ssh; chmod 700 ~/.ssh

a@A$ scp ~/.ssh/id_rsa.pub b@B:/home/b/.ssh/authorized_keys


3. 접속 테스트

a@A$ ssh b@B







SSH login without password

Your aim

You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.

How to do it

First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

a@A:~> ssh b@B mkdir -p .ssh
b@B's password: 

Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password: 

From now on you can log into B as b from A as a without password:

a@A:~> ssh b@B

A note from one of our readers: Depending on your version of SSH you might also have to do the following changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640

Keywords: ssh openssh password   Author: Mathias Kettner

Check_MK  MK


source - http://www.linuxproblem.org/art_9.html






$ chmod 700 ~/.ssh  반드시 해 주자


1.2.1.1 ssh 자동로그인

[account@master ~]$ssh-keygen -t dsa
(특별한 옵션없이 엔터 여러번으로 마무리) 
(생성된 개인 key는 매우 중요하므로 유출되지 않도록 잘 보관해야 합니다. )

  • target 서버로 복사
[account@master ~]$scp ~/.ssh/id_dsa.pub account@target:   (콜론에 주의)
account@target's password: (패스워드 입력)
id_dsa.pub              100% (생략)
[account@master ~]$
  • target 서버로 일단 로그인
$ssh account@target
account@target's password: (패스워드 입력)
[account@target ~]$
  • 마스터 서버 계정의 퍼블릭 키를 허용 키 목록에 등록
[account@target ~]$cat ~/id_dsa.pub >> ~/.ssh/authorized_keys2
  • 퍼미션 조정
[account@target ~]$chmod 700 ~/.ssh
[account@target ~]$chmod 644 ~/.ssh/authorized_keys2
  • 접속 종료후 재접속되는지 확인
[account@target ~]$exit
(접속종료)
[account@master ~]$ssh target
(자동접속)
[account@target ~]$
  • 안될경우 디버그
  • ssh 접속시 -vvv 등으로 메시지 확인해보기
  • 타겟 서버의 /etc/ssh/sshd_config 에서 아래 설정 확인
RSAAuthentication yes
PubkeyAuthentication yes

1.2.1.2 ~/.ssh/config 파일

  • 마스터 서버에서, 각 서버의 ssh 계정과 port 번호를 미리 적어둘 수 있음
  • 만약 $ ssh kim@target1 -p 30027 , $ ssh park@target2 -p 40027 로 접속해야 하는경우, 아래와 같이 ~/.ssh/config 파일을 만듬
  • 호스트의 키 저장 질문을 무시하는 옵션 추가하려면 "StrictHostKeyChecking no"을 넣어 주거나 명령어 실행시 옵션을 주면 됨 (ssh -o StrictHostKeyChecking=no userid@srv_ip ...)
[account@master ~]$cat ~/.ssh/config
StrictHostKeyChecking no

Host target1
        User kim
        Port 30027
Host target2
        User park
        Port 40027
[account@master ~]$
  • chmod 644 ~/.ssh/config 필요
  • 이렇게 적어두면, $ ssh target1 , $ ssh target2 만으로 접속이 가능해짐 


출처 - http://dev.naver.com/projects/dist







하루에도 몇번씩이나 들어가는 서버들, 매번 같은 패스워드 치기가 귀찮다.
패스워드가 어찌나 어렵던지~
한번은 서버장애가 났는데.. 게이트(gate server)조차 들어가는데 10번이나 틀려서
거의 미칠뻔(?) 한적이 있다. (오타대마왕 양군)

To set up password-free access to an OpenSSH Server

1. On your OpenSSH client machine:
1.1 ssh 버젼보기
[willow@willow ~]$ ssh -V
OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006

1.2 dsa 비밀키, 공개키 생성
[willow@willow .ssh]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/willow/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/willow/.ssh/id_dsa.
Your public key has been saved in /home/willow/.ssh/id_dsa.pub.
The key fingerprint is:
89:87:bb:79:eb:fe:3d:5a:9d:13:3b:fb:4b:0e:b0:e0 willow@willow.kr

1.3 생성된 리스트
[willow@willow .ssh]$ ls -al
합계 24
drwx------ 2 willow willow 4096 2월 19 10:50 ./
drwx------ 42 willow willow 4096 2월 19 10:45 ../
-rw-r--r-- 1 willow willow 2224 12월 5 17:52 known_hosts
-rw------- 1 willow willow 672 2월 19 10:50 id_dsa
-rw-r--r-- 1 willow willow 606 2월 19 10:50 id_dsa.pub

2. On the Open SSH server machice:
2.1 ssh 버젼보기
[mhyang@igate ~]$ ssh -V
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003

2.2 계정디렉토리에 .ssh 디렉토리를 생성
(보통 ssh를 이용해서 다른 서버를 접속한 경우가 있는경우 자동 생성되어 있다.)
client server 의 id_dsa.pub 의 내용을 authorized_keys 파일에 추가한다. (없다면 생성)
[mhyang@igate ~]$ ls -al
drwx------ 2 mhyang mhyang 4096 2월 19 11:10 .ssh <- 디렉토리 퍼미션 확인

2.3 authorized_keys 파일 퍼미션을 확인한다.
[mhyang@igate .ssh]$ ll
-rw-r----- 1 mhyang mhyang 606 2월 19 10:55 authorized_keys
-rw-r--r-- 1 mhyang mhyang 225 2월 19 10:42 known_hosts

3. Etc:
3.1 퍼미션때문에 로그인화면 나온경우 (설정확인하고..이래저래 당황했다. ㅡㅡ;;)
[willow@willow .ssh]$ ssh -l mhyang xxx.xxx.xxx.xxx -pXXXX
mhyang@xxx.xxx.xxx.xxx's password:

3.2 alias 적용해서 더 편하게 쓰장.
[willow@willow ~]$ vi .bashrc
alias igate='ssh -l mhyang xxx.xxx.xxx.xxx -pXXXX'
~
[willow@willow ~]$ source .bash_profile
[willow@willow ~]$ alias
alias igate='ssh -l mhyang xxx.xxx.xxx.xxx -pXXXX'
~


FROM URL http://nf.apac.edu.au/facilities/software/SSH/ssh-without-passwds.html

IMPORTANT URL http://pcandme.net/phpBB2/viewtopic.php?t=51
본문내용 :

less..

* SSH Authorized Key 사용법 
1. 인증키 사용하기 
인증키를 사용하는 것은 로그인 할때마다 암호를 직접 입력하는 것보다 더욱 안전하며, 하나의 암호로 여러 ssh서버에 접속할수 있는등의 장점을 가진다. 
1.1 인증키 만들기 
인증키는 ssh-keygen로 만든다. dsa 방식의 인증키를 만들기 위해 다음과 같이 실행한다. 
인용: 
# ssh-keygen -t dsa 

그러면 다음과 같이 키가 저장될 곳과 이름을 물어오는데 디폴트로 하려면 엔터를 치고 넘어가면 된다. 
인용: 
Generating public/private rsa1 key pair. 
Enter file in which to save the key (/home/youraccountname/.ssh/id_dsa): 

그런 다음 passphrase를 물어오는데 passphrase 같은 경우 엔터를 치면 디폴트로 사용하지 않는 상태가 된다. passphrase를 사용하려면 원하는 문구를 입력해주고 확인용으로 한 번 더 입력해주면 된다. passphrase 사용 시 접속할 때마다 입력하는 수고를 덜기 위한 방법으로 ssh-add와 ssh-agent를 사용하는 방법이 있는데 이것에 대해서는 1.3절에서 설명한다. 
인용: 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

입력을 완료하게 되면 다음과 같은 메시지와 함께 public key와 private key가 생성된다. 
인용: 
Your identification has been saved in /home/youraccountname/.ssh/id_dsa. 
Your public key has been saved in /home/youraccountname/.ssh/id_dsa.pub. 
The key fingerprint is: 
63:21:ee:ad:0a:7a:bf:68:51:1e:07:08:5d:de:78:0f youraccountname@hostname 

1.2 public key 등록 
~/.ssh/ 안에 한쌍의 키(default: id_dsa와 id_dsa.pub)가 생성되어 있을 것이다. 그 중 public key를 접속할 remote server들의 ~/.ssh/에 authorized_keys라는 이름으로 복사해준다. 
인용: 
# scp ~/.ssh/id_dsa.pub youraccountname@hostname.domain:~/.ssh/authorized_keys 

물론 이 때에는 scp를 사용하기 위해서 계정 암호를 입력해야 한다. 
이제 ssh 접속을 진행 해보면 계정암호가 아닌 인증키 암호를 물어볼 것이다. 만약 계정 암호를 물어본다면 authorized_keys의 퍼미션이 잘못되어 있는 것이므로, 일단 접속을 한 후 chmod 644 ~/.ssh/authorized_keys를 실행시켜 퍼미션을 변경하여 준다. 
openSSH는 두가지 프로토콜의 인증키를 동시에 쓰는것이 가능한데, 만들어진 publice key를 위와 같은 방법으로 remote server의 ~/.ssh/authorized_keys2 에 저장하면 된다. 
2. Authorized Key를 메모리에 상주 시키기 
다음 방법으로 Authorized Key를 메모리에 기억시켜 두면 처음 한 번만 passphrase를 입력하면 다음부터는 암호를 입력하지 않아도 같은 Authorized key를 사용하는 모든 서버들에 접속할수 있다. 물론 이 방법은 passphrase를 사용할 때만 해당된다. 
다음과 같이 실행한다. 
인용: 
# eval $(ssh-agent) 

그럼 다음과 같은 메세지를 보여줄 것이다. 
인용: 
Agent pid 31234 

위의 pid는 다를 수 있다. 다음으로 ssh-add를 실행한다. 
인용: 
#ssh-add 

그럼 다음과 같은 메시지가 출력된다. 
인용: 
Identity added: /home/youraccoutname/.ssh/id_dsa (youraccountname@hostname.domain) 

이제 인증키를 복사해둔 ssh서버에 접속하면 이 세션에서는 더 이상 암호를 묻지 않을 것이다.

less..


IMPORTANT URL http://ssalkong.com/bbs/view.php?id=linux_server&no=107
본문내용 :

less..


1. OpenSSH란?

Secure Shell (SSH)은 간단히 말하면 network을 타고 다른 computer에 login하거나, 다른 computer에서 
명령을 실행하거나, file을 전송하기 위한 program이다. Secure Shell은 기존의 telnet, rlogin, rsh, rcp를 대체
하기 위한 것이며, 이를 위해 보안상 '안전하지 않은' 채널 위로, 강력한 인증(authentication)과 '안전한' 통신
을 제공한다.
SSH에는 SSH1과 SSH2의 2가지 protocol이 있다. 물론 SSH2가 더 나중에 나온 protocol이기는 하지만, 
SSH2가 SSH1의 개량 version은 아니며, SSH1과 SSH2는 서로 완전히 다른 protocol이다. 가령, SSH1에서
는 encryption을 위해서 DES, 3DES, IDEA, Blowfish 같은 cyper를 사용하고, authentication을 위해서는 
RSA cyper를 이용하는데 비해, SSH2에서는 encryption에 3DES, Blowfish, Twofish, Arcfour, Cast128-cbc
를, authentication에 DSA를 사용한다.
SSH를 이용한 각종 보안 제품이 시장에 나와 있는데, 그 중 무료로 사용할 수 있도록 나온 것이 OpenSSH이
다. OpenSSH는 SSH protocol version 1.3, 1.5, 그리고 2.0을 지원한다.
OpenSSH는 현재 2개 team에서 관리/배포하고 있다. 한 team은 OpenBSD를 기반으로 하는 원래 개발 
team이며, 다른 한 team은 원래 개발 team에서 발표한 source를 여러 가지 다른 OS에 porting하는 역할을 한다. 
이 porting된 version은 'p' release라고 불리며, version을 보면 openssh-2.9p1.tar.gz와 같이 release 번호에 'p'가 
들어가 있는 것을 볼 수 있다.
       
2. OpenSSH 서버 설치&설정

1) 설치
http://www.openssh.com/portable.html에서 최신버전(openssh-3.5p1.tar.gz)을 다운받는다.

2) 설정 - /etc/ssh/sshd_config파일을 운영시스템에 맞도록 최적화한다. (보안책 p459 참고)
① PermitRootLogin no : ssh를 이용하여 root로 로그인하지 못하도록 반드시 no로 설정.
② StrictModes yes : ssh가 로그인을 받기 전, 각 사용자의 홈 디렉토리 실행 권한과 rhosts파일 검사여부 결정.
③ PasswordAuthentication no : 인증할 때 암호 기반 인증방법의 사용 여부를 결정. 반드시 no로 설정.
④ PermitEmptyPasswords no : 인증과정에서 암호가 입력되지 않은 계정에 대한 로그인 허용여부를 정의.  
                                서버에서는 암호인증을 사용하지 않으므로 안전을 위해 no로 설정.         
⑤ AllowUsers admin : 어떤 사용자가 ssh에 접근할 수 있는지를 정의하고 통제한다.

3. 클라이언트 사용법

1) OpenSSH 사용자 설정 - /etc/ssh/ssh_config파일을 시스템에 맞도록 최적화시킨다. (보안책 p455 참고)
① PasswordAuthentication no : 인증할 때 암호 기반 인증방법의 사용 여부를 결정. 반드시 no로 설정.
② FallBacktoRsh no : ssh 데몬을 이용한 연결이 실패했을 때 자동으로 rsh를 사용할지 여부를 결정.
                       rsh 서비스는 안전하지 못하므로 항상 no로 설정.
③ UseRsh no : rlogin/rsh 서비스가 호스트에 사용되는지에 대한 여부를 결정. 확실히 no로 설정.
④ StrictHost_KeyChecking yes : ssh가 ~/.ssh/known_hosts파일에 자동으로 새로운 호스트 키를 추가할지,  
             추가하지 않을지의 여부를 결정. yes로 설정하면 트로이 목마 공격에서 최대한의 보안을 확보.

2) OpenSSH 초기화 파일

▶ /etc/rc.d/init.d/sshd 스크립트 파일은 sshd demon을 로드할 때 독립 실행으로 구동하면 어떤 라이브러리도  
    공유하지 않기 때문에 로드하는데 소요되는 시간이나 스와핑이 감소한다. 이러한 방법은 시스템에서 sshd    
    demon을 시작하는데 가장 좋은 방법이므로 sshd를 시작할 때는 inetd나 Xinetd는 사용하지 않는 것이 좋다.

▶ 일단 OpenSSH 스크립트 파일이 생성되면 실행할 수 있도록 변경하는데 root 사용자만 변경할 수 있도록 한다.
      # chmod 700 /etc/rc.d/init.d/sshd
      # chown 0.0 /etc/rc.d/init.d/sshd

▶ 이제 이 파일을 부팅 시 자동으로 시작되도록 rc.d 디렉토리 아래에 링크 시켜준다.

3) 기본적인 사용방법

   # ssh -l <login_name> <hostname>

    ex) 접속할 ssh서버가 barammail.net이고 계정명이 shs80 이라고 한다면
       # ssh -l shs80 barammail.net

▶ 이제 다음과 같은 메세지와 함께 접속이 진행될 것이다.
    위 메세지는 ssh로 해당 서버에 처음 접속할 때만 나오는 메세지이며, 접속할 서버의 호스트 키가       
    ~/.ssh/known_hosts(ssh2의 경우 known_hosts2) 파일에 저장된다. 
    yes로 대답해주면, 계정 암호를 물어오고, 이제 텔넷과 동일한 작업을 할 수 있다.

4) 인증키 사용방법

인증키를 사용하는 것은 로그인 할 때마다 암호를 직접 입력하는 것보다 더욱 안전하며, 하나의 암호로 여러 
ssh서버에 접속할 수 있는 등의 장점을 가진다.

▶ ssh-keygen로 인증키 만들기
    
    키가 저장될 곳과 이름을 물어 오는데 디폴트로 enter 치고 넘어가면, 다음과 같이 인증키 암호를 물어온다.

    원하는 암호를 두 번 입력해주면 ~/.ssh/ 안에 한 쌍의 개인키와 공개키(id_dsa와 id_dsa.pub)가 
    생성되어 있을 것이다. 

       cf> 인증키 생성 시 인증키 암호를 공백으로 (passphrase를 물어올 때 그냥 enter 친다) 만들 수도 있는데, 
           이것은 ssh 접속 시 암호를 입력하지 않아도 그냥 접속이 되므로 편리할 수는 있으나, 인증키가 어떠한 
           경로로든 유출되었을 경우를 생각 해보면 피해야 할 것이다. 

    이제 이 인증키를 접속할 원격 서버들의 ~/.ssh/에 authorized_keys2라는 이름으로 복사한다.

        # scp ~/.ssh/id_dsa.pub shs80@barammail.net:.ssh/authorized_keys2

    * 만약 인증키 암호가 아닌 계정 암호를 물어보면 authorized_keys의 퍼미션이 잘못되어 있는 것이므로, 
       일단 접속 후 chmod 644 .ssh/authorized_keys2로 수정해준다.
  
    * 서버가 ssh1 프로토콜을 지원한다면 옵션을 제거하고 ssh-keygen로 인증키를 생성한다. 그러면 identity와        
        indentity.pub가 생성되고 위와 같은 방법으로 원격 서버에 ~/.ssh/authorized_keys로 저장하면 된다.


     * 서버가 지원한다면 되도록 SSH2 프로토콜을 사용하도록 한다. SSH1 보다 더욱 안전하고, 성능이 좋다.


5) SSH를 이용한 파일 복사-scp

  보안 복사 프로그램으로 로컬 시스템에서 원격서버(또는 반대)로 파일을 복사할 때 안전한 방법을 제공하는 유틸리티다.
▶ 복사하려는 파일명을 'test' 라고 하고 접속하려는 원격 서버의 주소를 barammail.net, 쉘 계정을 shs80   
     이라고 했을 때, test 파일을 barammail.net의 shs80계정 /tmp디렉토리에 복사하려면......
          # scp test shs80@barammail.net:/tmp
    
▶ ~/.ssh/config 파일에 다음과 같이 barammail.net의 계정을 설정해 놓았다면,

     간단하게   # scp test fbc:/tmp 하면된다.

     * scp 옵션(-r,-p 등)을 써서 파일이나 디렉토리를 복사할 수도 있다.


< 참고한 사이트 >
http://www.openssh.com
http://kdtp.kldp.org/KoreanDoc/html/SSH-KLDP/index.html  (임은재 'SSH Howto')
http://www.iflu.net/study/lecture12/12_index.html  (SSH 완벽가이드)
http://www-903.ibm.com/kr/techinfo/pseries/tech/openSSH.html  (IBM 기술정보)


출처 - http://seeds.tistory.com/193




Posted by linuxism
,