Passwordless access for ssh and sftp(Passwordless access for ssh and sftp)

                                                                         

Password less access for ssh and sftp , How to do sftp & ssh without password – Step by Step
This a real time example of configuring password less access for two users . The user ‘web’ in this case needs a secure password less access to another user suresh in a server ‘onlinetraining’
.
Follow the Steps to configure secure password less access
Check the current ssh connectivity status for suresh@onlinetraining from localhost
[web@localhost ~]$ ssh suresh@onlinetraining
suresh@onlinetraining’s password: 

Permission denied, please try again.
As expected it prompted for password
1. Generate the public key private key pair 
Generate the public key private key pair for the local host as following , Press enter for default file names and no
pass phrase options. The command here generates RSA type keys.
[web@localhost ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/web/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/web/.ssh/id_rsa.
Your public key has been saved in /home/web/.ssh/id_rsa.pub.
The key fingerprint is:
5e:30:d3:1a:00:c5:0b:29:96:ac:3e:42:20:dc:af:38 web@localhost.localdomain
You can run the command ssh-keygen from any directory but the id files will be generated in .ssh dir of user’s home directory.
2. Change directory to .ssh directory.
[web@localhost ~]$ cd /home/web.ssh

You will see two files starting with id_rsa. id_rsa is the private key and id_rsa.pub is public key. Check the date time stamp of these files to make sure these are the ones you generated recently.
/.ssh[web@localhost .ssh]$ ls -la
total 32
drwx—— 2 web web 4096 Dec 7 22:05 .
drwx—— 34 web web 12288 Dec 7 22:04 ..
-rw——- 1 web web 1675 Dec 7 22:05 id_rsa
-rw-r–r– 1 web web 407 Dec 7 22:05 id_rsa.pub
-rw-r–r– 1 web web 391 Dec 7 22:03 known_hosts
/.ssh[web@localhost .ssh]$ date
Tue Dec 7 22:05:45 PST 2010
3. Copy the rsa public key to the remote host . You have to copy the public key file in to .ssh of the user home directory and if .ssh directory is not there , create it as in the example below.
You need to enter sftp/ssh password .
/.ssh[web@localhost .ssh]$ sftp suresh@onlinetraining
Connecting to onlinetraining…
suresh@onlinetraining’s password:
sftp> pwd
Remote working directory: /home/suresh
sftp> cd .ssh
Couldn’t canonicalise: No such file or directory
sftp> mkdir .ssh
sftp> cd .ssh
sftp> put id_rsa.pub
Uploading id_rsa.pub to /home/suresh/.ssh/id_rsa.pub
id_rsa.pub 0% 0 0.0KB/s –:– ETAid_rsa.pub 100% 407 0.4KB/s 00:00
sftp>
4. login to the remote host with password
Once file is copied over , login to the remote host using ssh and password and go to .ssh directory under user home directory.
/.ssh[web@localhost .ssh]$ ssh suresh@onlinetraining
suresh@onlinetraining’s password:
suresh@onlinetraining:~[suresh@onlinetraining ~]$ cd .ssh
[mailto:suresh@onlinetraining:~/.ssh%5bsuresh@onlinetraining]suresh@onlinetraining:~/.ssh[suresh@onlinetraining .ssh]$ pwd
/home/suresh/.ssh
[mailto:suresh@onlinetraining:~/.ssh%5bsuresh@onlinetraining]suresh@onlinetraining:~/.ssh[suresh@onlinetraining .ssh]$ ls -l
total 4
-rw-r–r– 1 suresh suresh 407 Dec 7 22:06 id_rsa.pub
5. Rename the public key file to authorized_keys ;
if the authorized_keys file already exists then append the new keys to the existing file using,
cat id_rsa.pub >> authorized_keys .
Don’t use vi or editor to open , append and save these key files as any extra character/newline would corrupt these files.
[mailto:suresh@onlinetraining:~/.ssh%5bsuresh@onlinetraining]suresh@onlinetraining:~/.ssh[suresh@onlinetraining.ssh]$ mv id_rsa.pub authorized_keys

You can see the contents using cat command
[mailto:suresh@onlinetraining:~/.ssh%5bsuresh@onlinetraining]suresh@onlinetraining:~/.ssh[suresh@onlinetraining.ssh]$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArVWhE0L2FXNvmggZgqmGU
LVrcE4X7WQr6scSuU5FCQUsXzYjyOL8FbUIIkBeLLMIrV7mYa+
xuszHcvnAho/42/e4r5by8LVMyh0AAo7nketemkO/2ZiUXZhww7tySxgcI5U5L5PDmTCyF7vxLlJ0rGb7Ky//DtpKrBui5P4gIrKBeiA2TlbEL9UrQZ8HgTU3iSGtfUXH0O
26iLSWi6Tf40hEazvvVYESHPSBjUPIMqUGabtz1kKMDQB5x
C+F2MZ4lUCmgK2NexrhVWOrp7ODS1GlKsjSv6NSxOIVW0je
V00ZW9Fvgz865g+fakBITqYP76ptPIVXEps+91ABRSwggQ== 
web@localhost.localdomain
6. Change the key file and directory permissions
ssh is very sensitive to permissions so you have to change the key file and directory permissions for it to work.
6a : Change authorized_keys to 600 permissions

[mailto:suresh@onlinetraining:~/.ssh%5bsuresh@onlinetraining]suresh@onlinetraining:~/.ssh[suresh@onlinetraining.ssh]$ chmod 600 authorized_keys
[mailto:suresh@onlinetraining:~/.ssh%5bsuresh@onlinetraining]suresh@onlinetraining:~/.ssh[suresh@onlinetraining.ssh]$ ls -ltr
total 8
-rw-r–r– 1 suresh suresh 407 Dec 7 22:06 id_rsa.pub
-rw——- 1 suresh suresh 407 Dec 7 22:08 authorized keys
[mailto:suresh@onlinetraining:~/.ssh%5bsuresh@onlinetraining]suresh@onlinetraining:~/.ssh[suresh@onlinetraining .ssh]$ cd ..
6b : Change .ssh directory to 700 permission
suresh@onlinetraining:~[suresh@onlinetraining ~]$ chmod 700 .ssh
6c :Verify permissions and log out . 
suresh@onlinetraining:~[suresh@onlinetraining ~]$ logout
Connection to localhost closed.
8. Moment of truth : Try a ssh

/.ssh[web@localhost .ssh]$ ssh suresh@onlinetraining
Last login: Tue Dec 7 22:07:04 2010 from localhost.localdomain
suresh@onlinetraining:~[suresh@onlinetraining ~]$ pwd
/home/suresh
Here we have no password secure access working .

The most common problems can be
1. Incorrect permission for .ssh and authorized_keys file
2. Corrupt key file , regenerate and copy again.

Unix written test for experience

                 


1. What is a context switch?
a) Kernel switches from executing one process to another.
b) Process switches from kernel mode to user mode.
c) Process switches from user mode to kernel mode.
d) None of the above

Answer:a
2. Pid of init process
a) 0                         
b) 1
c) 32767              
d) none of the above

Answer:b
3. What is the default maximum number of processes that can exist in Linux?
a) 32768       
b) 1024                
c) 4096       
d) unlimited

Answer:a
4. How do you get parent process identification number?
a) waitpid
b) getpid()
c) getppid()
d) parentid()

Answer:c
5. Parent process id of a deamon process is_________________.

Answer:1
6. The process which terminates before the parent process exits becomes
a) Zombie
b) Orphan
c) Child
d) None of the above

Answer:a
7. Return value of fork() system call can be:
a) -1,<0,0
b) -1,>0,0

Answer:b
8. If the fork() system call returns -1, then it means?
a) No new child process is created
b) The child process is an orphan
c) The child process is in Zombie

Answer:a
9. Fork returns _____ to parent process on success
a) 0 
b) child process id
c) parent process id
d) none

Answer:b
10. How many times printf() will be executed in the below mentioned program?
    main() {
        int i;
        for (i = 0; i < 4; i++)
        fork();
   
        printf(“my pid = %d\n”, getpid());
    }
a) 4
b) 8
c) 16
d) 32

Answer:c
11. What is the output of the below code?
    void exit_handler1();
    void exit_handler2();
    int main() {
        int pid;
        atexit(exit_handler1);
        atexit(exit_handler2);
        pid = fork();
        if(pid == 0) {
           _exit(0);
        } else {
            sleep(2);
            exit(0);
        }
        return 0;
    }
a) Only child executes the exit_handler 1 and 2.
b) Only parent executes the exit_handler 1 and 2.
c) Both parent and child executes the exit_handler 1 and 2.
d) Neither parent nor child executes the exit_handler 1 and 2.

Answer:b
12. What is output of the following program?
 
    int main() {
        fork();
        fork();
        fork();
        if (wait(0) == -1)
            printf(“leaf child\n”);
    }
a) “leaf child” will be printed 1 times
b) “leaf child” will be printed 3 times
c) “leaf child” will be printed 4 times
d) “leaf child” will be printed 8 times

Answer:c
13. Which niceness value among the following indicate most favorable scheduling?
a) 0      
b)  19    
c)  5       
d)  -20

Answer:d
14. The maximum time slice that can be given to a process in Linux (where tick is 10ms) is
a) 150ms  
b) 10ms   
c) 300 ms   
d) 600ms

Answer:d
15. Nice can be used by an ordinary process to
a) increase the priority of a process
b) decrease the priority of a process
c) increase or decrease the priority of a process

Answer:b
16. Which one can be a real time schedule policy?
a) SCHED_FIFO
b) SCHED_SPF
c) SCHED_OTHER
d) SCHED_FILO

Answer:a
17. In Linux kernel-2.6 Real time priority ranges from
a) 0 to 99
b) 0 to 139
c) -20 to 19
d) 100 to 139

Answer:a
18. Solaris real time class priority is
a) 0-59
b) 60-99
c) 100-159
d) 160-169

Answer:c
19. Solaris System class priority is
a) 0-59
b) 60-99
c) 100-159
d) 160-169

Answer:b


Amazon written for experience

                                             
For the below written test answer defined with "*" at the end of the options 

NULL is
Top of Form
  • the same as 0 for integer
  • the same as blank for character       *
  • the same as 0 for integer and blank for character
  • the same as 0 for integer and blank for character
The basic function of ____________ is to search for files(or other units of text) that contain a pattern.
Top of Form
  • awk  *
  • search
  • cat
  • cmp
  What will be the output of the program?

class SSBool
{
    public static void main(String [] args)
    {
        boolean b1 = true;
        boolean b2 = false;
        boolean b3 = true;
        if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 */
            System.out.print("ok ");
        if ( b1 & b2 | b2 & b3 | b2 | b1 ) /*Line 10*/
            System.out.println("dokey");
    }
}

Top of Form
  • ok
  • dokey  *
  • No output is produced
  • Compilation error
  What does the literal “$?” mean in Shell script?
Top of Form
  • Exit status of the previous command executed
  • Exit status of the last command executed   *
  • Exit status of the first command executed
  • Exit status of the last command failed
  If 10 bulls can plough 20 identical fields in 3 days working 10 hours a day, then in how many days can 30 bulls plough 32 same identical fields working 8 hours a day?
Top of Form
  • 2  *
  • 4
  • 8
  • 10
 What will be the output of the following query? SELECT DECODE(TRANSLATE('A','1234567890','1111111111'),'1','YES', 'NO' ) from DUAL;
Top of Form
  • NO  *
  • YES
  • 1234567890
  • 1111111111
Table Employee has 10 records. It has a non-NULL SALARY column which is also UNIQUE. The SQL statement prints? SELECT COUNT(*) FROM Employee WHERE SALARY > ANY (SELECT SALARY FROM Employee);
Top of Form
  • 10
  • 9  *
  • 1
  • 0
  What is the output of the following program?
x = 3; y = 5; z = 10;
if [( $x -eq 3 ) -a ( $y -eq 5 -o  $z -eq 10 )]
then
    echo $x
else
    echo $y
fi

Top of Form
  • 1
  • 3
  • 5
  • Error  *
A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?
Top of Form
  • 120 metres
  • 180 metres
  • 324 metres
  • 150 metres  *
Predict output of the following program

#include <stdio.h>
typedef struct film{
    int size;
    int pixel;
    float price;
}xyz,pqr;

struct film *jadu(){
    static xyz one={231,12,900.0},*p=&one;
    return p;
}

int main(){
    pqr *ptr;
    ptr=jadu();
    printf("%d",ptr->pixel);
    return 0;
}

Top of Form
  • 231
  • 12  *
  • 900.0
  • Compilation error
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form

What will be the output of the following query? SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'), 'AN', '*'),'','TROUBLE') FROM DUAL;
  • ATHEN
  • **ATHEN
  • ATHEN***
  • None of the above  *

How will you list all the files within a directory including hidden files aka (.) dot files?
Top of Form
  • ls –a   *
  • ls –h
  • ls –q
  • ls –t
How to make any script file executable?
Top of Form
  • $chmod 655 *.sh
  • $chmod 765 *.sh
  • $chmod 755 *.sh  *
  • $chmod 754 *.sh
How to find current running processes in Unix server?
Top of Form
  • $ ps –ef *
  • $ ds –ef
  • $ du –ef
  • $ ls –ef
Bottom of Form

The least significant bit of the binary number, which is equivalent to any odd decimal number is
Top of Form
  • 0
  • 1   *
  • 1 or 0
  • None
Which OSI layer is responsible for Encryption and Decryption?
Top of Form
  • A) Network Layer   *
  • A) Network Layer
  • C) Data Link Layer
  • D) Presentation Layer
Which of the following memories has the shortest access time?
Top of Form
  • Cache memory *
  • . Magnetic Bubble memory
  • Magnetic core memory
  • RAM
Expand the following abbreviation – USB?
Top of Form
  • a) Universal sequence bit
  • b) Universal serial bus *
  • c) Universal sequence byte
  • d) Unique serial bit
How many times printf() will be executed in the below mentioned program? main() { int i; for (i = 0; i < 4; i++) fork(); printf(“my pid = %d\n”, getpid()); }
Top of Form
  • 4
  • 8
  • 16  *
  • 32
Bottom of Form

 What will be the output of the below program?

#include<stdio.h>
int main(){
int far *p=(int *)0X70230000;
int far *q=(int *)0XB0210000;
int near *x,near*y;
x=(int near *)p;
y=(int near *)q;
if(x==y)
printf("Both pointer are equal");
else
printf("Both pointer are not equal");

    return 0;
}

Top of Form
  • Both pointers are equal
  • Both pointer are not equal
  • Segmentation fault
  • Compilation error  *
What is the difference between linux file system and windows file system?
Top of Form
  • A) Under Linux, the various partitions are detected at boot and assigned a drive letter whereas Under windows, unless you mount a partition or a device, the system does not know of the existence of that partition or device. *
  • B) Under Windows, the various partitions are detected at boot and assigned a drive letter whereas Under Linux, unless you mount a partition or a device, the system does not know of the existence of that partition or device
  • C) Under Windows, the various partitions are detected at reboot and assigned a drive letter whereas Under Linux, unless you mount a partition or a device, the system does not know of the existence of that partition or device
  • D) Under Windows, the various partitions are detected at reboot and assigned a drive letter whereas Under Linux, you mount a partition or a deviceBottom of Form
A bitwise operation 'f' has an interesting characteristic, such that, if f(a,b) = c, it always turns out to be the case that f(b,a) = c; f(a,c) = b; f(c,a) = b; f(b,c) = a; f(c,b) = a.
a) Which of these functions could 'f' possibly be?
Top of Form
  • f(a,b) = a XOR b  *
  • f(a,b) = a + b
  • f(a,b) = a - b
  • f(a,b) = a * b
the following crontab file entry
0 17 * * 1,2,3,4,5 /usr/sbin/ckbupscd >/dev/console 2>1
The above entry says to run /usr.. at what time
Top of Form
  • 17 mins pass midnight
  • 5 pm on weekday of each month *
  • Midnight on the 17 day of each month
  • On the 17 day of each month at 1,2,3,4 and 5 pm
Bottom of Form

 How would you sort a file called shopping on column 3?
Top of Form
  • A) Sort –n 3 shopping
  • B) Sort –K 3 shopping *
  • C) Sort –c 3 shopping 
  • D) Sort –c3 shopping
What is the output of following program?

#include <stdio.h>
void print(int n, int j)
{
   if (j >= n)
      return;
   if (n-j > 0 && n-j >= j)
       printf("%d %d\n", j, n-j);
   print(n, j+1);
}
 int main()
{
    int n = 8;
    print(n, 1);
}

Top of Form
  • 1 7 2 6 3 5 4 4 4 4   *
  • 1 7 2 6 3 5 4 4
  • 1 7 2 6 3 5
  • 1 2 3 4 5 6 7 8
 What is 2NF in normalization?
Top of Form
  • A) if the domain of each attribute contains only atomic (indivisible) values, and the value of each attribute contains only a single value from that domain.[
  • if all the attributes in a table are determined only by the candidate keys of that table and not by any non-prime attributes
  • If no non-prime attribute is dependent on any proper subset of any candidate key of the table  *
  • D) None of above
A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?
Top of Form
  • 120 metres
  • 180 metres
  • 324 metres
  • 150 metres  *
 Predict the output of the following program

#include <iostream>
usingnamespacestd;
intmain()
{
    constchar* p = "12345";
    constchar**q = &p;
    *q = "abcde";
    constchar*s = ++p;
    p = "XYZWVU";
    cout << *++s;
    return0;
}

Top of Form
  • a
  • c
  • b
  • D) Garbage value  *
 Predict output of the following program

#include<iostream>
using namespace std;
class Test
{
protected:
    int x;
public:
    Test (int i):x(i) { }
    void fun() const  { cout << "fun() const " << endl; }
    void fun()        { cout << "fun() " << endl;     }
};

int main()
{
    Test t1 (10);
    const Test t2 (20);
    t1.fun();
    t2.fun();
    return 0;
}

Top of Form
  • Compilation error
  • fun() fun()
  • fun() const fun()
  • fun() fun() const  *
Bottom of Form

   What does the following query find?

(SELECT DISTINCT r.sid
FROM boats b, reserves r
WHERE b.bid = r.bid
AND b.color = 'red')
MINUS
 (SELECT DISTINCT r.sid
FROM boats b, reserves r
WHERE b.bid = r.bid
AND b.color = 'green');

Top of Form
  • Find the sailor IDs of all sailors who have reserved red boats but not green boats
  • Find the sailor IDs of atleast one sailor who have reserved red boats but not green boats  *
  • Find the sailor IDs of at most one sailor who have reserved red boats but not green boats
  • None of the above
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form

 Size of IPv6 address is
Top of Form
  • 4 bytes
  • 8 bytes
  • 6 bytes
  • 16 bytes  *
What is the probability of getting a sum 9 from two throws of a dice?
Top of Form
  • 1/6
  • 1/8
  • 1/9  *
  • 1/12
What will be output of following program?

#include<stdio.h>
int main(){
static int a=25;
void cdecl conv1() ;
void pascal conv2();
conv1(a);
conv2(a);
return 0;
}
void cdecl conv1(int a,int b){
printf("%d %d",a,b);
}
void pascal conv2(int a,int b){
printf("\n%d %d",a,b);
}

Top of Form
  • 25 0 0 25
  • 25 <null> <null> 25
  • Error will occur   *
  • 25 -99999999 -99999999 25
Which command puts a script to sleep untill a signal is received?
Top of Form
  • sleep
  • suspend   *
  • disown
  • break
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form
Bottom of Form