Thursday, April 10, 2014

Unix - SSH/SCP

  • Check SSH server running:
    # cat /etc/rc.conf | grep ssh
    sshd_enable="YES"

  • SSH access to a remote machine:
    #/$ ssh username@remoteMachine

    'remoteMachine' is the DNS resolvable hostname of the remote host. IP address can also be used instead of the remote machine's hostname.

  • Securely transfer file over SSH:
    #/$ scp -q -C -l 80000 username@remoteMachine:/home/username/test.txt \
    /home/username/. 

  • Enable root access over SSH (only if it is essential):
    # vi /etc/ssh/sshd_config
    PermitRootLogin yes
    
    # service sshd restart  (or, # /etc/rc.d/sshd restart) 

  • Generate and copy SSH keys:
    #/$ cd ~
    #/$ ssh-keygen -t rsa
    #/$ scp ~/.ssh/id_rsa.pub remoteMachine:.ssh/authorized_keys 

    'RSA' is used here as authentication mechanism. Similarly 'DSA' can also be used.

  • Verify whether SSH key is working:
    #/$ ssh remoteMachine hostname

    Displays remote machine's hostname without a password prompt.

  • Monitoring/tracing SSH/SCP activities:
    # cat /var/log/auth.log
    Displays detailed log.


Note: Unix commands and file locations used here have been tested on FreeBSD systems.

No comments:

Post a Comment